Can somebody please eplain why a weekly cron job I’d assumed would run at 06:47 on Sunday morning in fact ran at 00:10 on Tuesday morning?
This is a fairly virgin Debian Stretch box (been up a while waiting for use).
I have the following crontab:
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) #
And the following anacrontab:
# /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin HOME=/root LOGNAME=root # These replace cron's entries 1 5 cron.daily run-parts --report /etc/cron.daily 7 10 cron.weekly run-parts --report /etc/cron.weekly @monthly 15 cron.monthly run-parts --report /etc/cron.monthly
/usr/sbin/anacron exists and is executable.
Tue 29 Jan 15:26:23 UTC 2019
15:26:30 up 41 days, 7:03, 2 users, load average: 0.00, 0.00, 0.00
Syslog shows the weekly cronjob running at 00:10 this morning (Tuesday):
Jan 29 00:10:10 RT-ARCHIVE anacron: Job `cron.weekly' started Jan 29 00:10:10 RT-ARCHIVE anacron: Updated timestamp for job `cron.weekly' to 2019-01-29
Why this time on a Tuesday? If the system had been freshly booted I might understand it playing catchup via anacron, but it hasn’t.
Also, the job didn’t run on the Sunday, just to make that clear also.
I’ve used cron in the past without issue, what am I missing???
The three entries in
/etc/crontab run only when
/usr/sbin/anacrontab is not present or not executable.
Notice that they begin with
test -x /usr/sbin/anacrontab. This runs first, then because they are followed by
||, the following runs only when the previous command fails.
As the comment in the
anacrontab file also states, it overrides those three entries.
Thus your weekly entry in anacrontab runs every 7 days with a 10 minute delay. Because you didn’t specify a
START_HOURS_RANGE, they run at the specified number of minutes past midnight.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.