What time does cron.monthly jobs run in SLES?

Posted on

Problem :

doc says cron.monthly will be scheduled according to the first run time and it compares /var/spool/cron/lastrun/cron.monthly with current time to run. Question is will it run according to the DAILY_TIME directive in /etc/sysconfig/cron file or the /var/spool/cron/lastrun/cron.monthly time. If it follows /var/spool/cron/lastrun/cron.monthly should I have to touch the file when I want the job to be scheuled???

Solution :

When does cron run monthly cronjobs?

cron starts monthly cronjobs once a month at /var/spool/cron/lastrun/cron.monthly‘s modification time (or more exactly, sometime within a 15-minute range after that time).

You can see that in /usr/lib/cron/run-crons, which is started every 15 minutes in /etc/crontab:

# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
-*/15 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1

When dealing with monthly cronjobs /usr/lib/cron/run-crons:

  1. Checks whether cron.monthly in /var/spool/cron/lastrun/ is older than one month.

  2. Skips monthly cronjobs if it’s not.

  3. Otherwise, deletes the lock file:

    eval find $SPOOL/$BASE $TIME | 
              xargs --no-run-if-empty rm

    adds the monthly cronjob to the run list:

    if test ! -e $SPOOL/$BASE ; then
        # accept this dir, if it isn't empty 
        LIST=`find $CRONDIR ! -type d`
        if [ ! -z "$LIST" ] ; then
            RUN="${RUN} ${TIME_EXT}"

    and runs the jobs.

How can I schedule monthly cronjobs?

  • If you want the monthly cronjobs to run now (that is, in the next 15 minutes), delete /var/spool/cron/lastrun/cron.monthly.

  • If you want the monthly cronjobs to run at say, 3am starting today, do:

    $ touch -d "$(date -d "3am last month")" /var/spool/cron/lastrun/cron.monthly

    Modify the command above to your needs.

The DAILY_TIME variable

The DAILY_TIME variable only applies to daily cron jobs, as can be seen in /usr/lib/cron/run-crons and documented in /etc/sysconfig/cron:

# At which time cron.daily should start. (...)

Leave a Reply

Your email address will not be published.