0

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.

Date:

Tue 29 Jan 15:26:23 UTC 2019

Uptime:

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[48734]: Job `cron.weekly' started
Jan 29 00:10:10 RT-ARCHIVE anacron[49100]: 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???

EDIT:

Just as a note to anyone arriving here, I'd to date only (knowingly) used cron, not anacron. Following this post I realise the newer virtual servers I've been provided with have anacron installed by default, whereas the older ones don't. According to the Debian Wiki, anacron is:

installed by default by Debian-Installer on laptops, and with the desktops task

So perhaps our IT guys have started setting them up differently ...

1
  • 7 10 cron.weekly run-parts --report /etc/cron.weekly would appear to define the 00:10 job.
    – ceejayoz
    Jan 29, 2019 at 15:39

1 Answer 1

2

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.

2
  • Ok thanks. I'd assumed anacron would honour the timinings specified in /etc/crontab if possible, i.e. if the machine hadn't been powered off at the scheduled time for cron.weekly. Given this machine should be constantly up I might disable anacron, or would you recommend against that?
    – whoasked
    Jan 30, 2019 at 7:32
  • This particular configuration appears to be Debian-specific; none of my CentOS based systems have anacron configured to prevent the hourly, daily, weekly cron jobs from running. It's a very strange design decision, but Debian is chock full of those. Have you considered switching to another distro? Jan 30, 2019 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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