What's new

How to add CRON entry in syslog file

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

itibi

Regular Contributor
Hi!
Question on Asus RT-AC3200 running ASUSWRT-Merlin 384.13_10

I just notice that my syslog file does NOT contains a CRON entry
for every cronjob execution (like my other Uni* systems)

How can it be done ?

Something like:
Nov 18 04:17:01 router CRON[92660]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
 
The cron in the firmware is (i think) part of busybox not like acron or something.

You would need to add a 'logger' command along with it. 'Logger' allows you to push your own things to the syslog.
Kine nearly all my commands (cron or otherwise) have 'logger' lines to make it a bit easier to debug.

Code:
#!/bin/sh
FILENAME=`basename "$0"`


# fake-hwclock load
if [ -f /jffs/scripts/fake-hwclock ] && [ -f /jffs/fake-hwclock.data ]; then
    logger -t CustomScript:$FILENAME "fake-hwclock-load"
    /jffs/scripts/fake-hwclock load
fi

logger -t CustomScript:$FILENAME "fake-hwclock-load"
 
@unsynaps:

nice and easy ;-)

Great suggestion. I will follow your recommendation for my own scripts.

Any solution for "system" scripts ?
as is
Nov 18 04:17:01 router CRON[92660]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
 
Years ago it used to log all cron events but people complained that it was filling up their logs: https://www.snbforums.com/threads/supress-log-output.21733/

So at some point the cron log verbosity level was changed to 9 to suppress the messages. It's hard-coded.

You can temporarily change it back to the default level (8) as follows:
Code:
killall crond; crond

The make the change permanent you'd have to put that in a user script.
 
@unsynaps:

nice and easy ;-)

Great suggestion. I will follow your recommendation for my own scripts.

Any solution for "system" scripts ?
as is
Nov 18 04:17:01 router CRON[92660]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
In the past, I've had the need to run some cron jobs that log their specific scheduled runs in the system log, and sometimes the same job runs at different times with different parameters, so to make things simpler I created a helper script that can do this for any cron job that I want.

The system log entries would look something like this:
Code:
...
Nov 19 01:10:01 CRON_[26030]_[#CronJobRUN1#]: [10  1  *  *  *  /jffs/scripts/CRONs/CronJobRun.sh -Run1 -Arg1]
...
Nov 19 01:20:00 CRON_[26073]_[#CronJobRUN2#]: [20  1  *  *  *  /jffs/scripts/CRONs/CronJobRun.sh -Run2 -Arg2]
...
Nov 19 01:30:02 CRON_[26112]_[#CronJobRUN3#]: [30  1  *  *  *  /jffs/scripts/CRONs/CronJobRun.sh -Run3 -Arg3]
...
Nov 19 01:40:00 CRON_[26157]_[#CronJobRUN4#]: [40  1  *  *  *  /jffs/scripts/CRONs/CronJobRun.sh -Run4 -Arg4]
...
Nov 19 01:50:00 CRON_[26202]_[#CronJobRUN5#]: [50  1  *  *  *  /jffs/scripts/CRONs/CronJobRun.sh -Run5 -Arg5]
...

Perhaps this helper script might be overkill for your purposes, but if you're interested I can provide it (you do need to have separate scripts for your own cron jobs), and you can determine if it meets your needs.

So for example, if you want to run a cron job that calls the following commands:
cd / && run-parts --report
you would need to create its own shell script:
Bash:
#!/bin/sh
#############################################
# RunPartsReport.sh
#############################################

## Add here my CRON helper script ##
CronJobHelper="/jffs/scripts/CRONs/CronJobHelper.sh"
if [ -f "$CronJobHelper" ] ; then source $CronJobHelper ; fi

cd / && run-parts "$1"

#EOF#

Then you add the cron job as usual (e.g. in the services-start script):
Bash:
cru a RunPartsJob "0  *  *  *  *  /jffs/scripts/RunPartsReport.sh --report"
 
Years ago it used to log all cron events but people complained that it was filling up their logs: https://www.snbforums.com/threads/supress-log-output.21733/

So at some point the cron log verbosity level was changed to 9 to suppress the messages. It's hard-coded.

You can temporarily change it back to the default level (8) as follows:
Code:
killall crond; crond

The make the change permanent you'd have to put that in a user script.

Hi! @ColinTaylor,

I tried your suggestion; crond is now running with default value
but I still (after 24 hours) get NO crond entry in my syslog.log file !!

Any ideas ?
 
Strange. It works for me, but then I've just noticed you're running an obsolete firmware version so maybe there are differences.

Have you changed the "Log only messages more urgent than" (System Log - General Log) setting?

Try this:
Code:
ps w | grep crond
cru l
grep crond /tmp/syslog.log
 
Last edited:
Here are the results:

# ps w | grep crond
6232 user 1444 S crond

# cru l
MAILTO="..hidden.." #MAILTO#
CRON_TZ=EST #TZ#
0 6 * * * /jffs/scripts/merlin-update-notification #merlin-update-notification#
16 * * * * /jffs/scripts/spdmerlin-notification #spdmerlin-notification#
55 4 * * * /jffs/scripts/general-update-notification #general-update-notification#
*/10 * * * * /jffs/scripts/ntpmerlin generate #ntpMerlin#
*/5 * * * * /jffs/scripts/dn-vnstat generate #dn-vnstat_generate#
59 23 * * * /jffs/scripts/dn-vnstat summary #dn-vnstat_summary#
12,42 * * * * /jffs/scripts/spdmerlin generate #spdMerlin#
30 12 * * * service restart_letsencrypt #LetsEncrypt#

# grep crond /tmp/syslog.log
Nov 20 11:59:55 crond[266]: time disparity of 2391070 minutes detected
Nov 20 12:13:14 crond[266]: time disparity of 2391128 minutes detected

So nothing obvious,

I don't think that it is caused by the time disparity

Maybe, it is just obsolete and that info is not available

Don't you think so ?
 

Attachments

  • 1669010950283.png
    1669010950283.png
    20.8 KB · Views: 56
The first two lines of your crontab (MAILTO and CRON_TZ) are unsupported and shouldn't be there. I imagine they might be preventing the following crontab lines from running. EDIT: I've just tested this and it just ignores those lines.

Change "Log only messages more urgent than" to "debug". IIRC the crontab messages are at the info level.
 
Last edited:
PS: The MAILTO line was to send me an email in case any crond command fails.

---
Setting to "debug" as suggested.

Et voilà!!

Bravo, it works. Thanks :)

I will let it run for a couple of days and see how it fill my logs.

Thanks again, you are the greatest ;)
 
PS: The MAILTO line was to send me an email in case any crond command fails.
Yeah, as I said, it's not a supported option. The router isn't a Linux distro. It uses busybox which has a more restricted command set. The router's busybox version of crond doesn't support CRON_TZ and wasn't compiled with sendmail support.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top