Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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???

share|improve this question

1 Answer 1

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}"
        fi
    fi
    

    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. (...)
DAILY_TIME=""
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.