0

My /etc/cron.daily scripts seem to be executing far later from what I understand they should. I am in Ubuntu and anacron is installed.

If I do a sudo cat /var/log/syslog | grep cron I get something like:

Aug 23 01:17:01 mymachine CRON[25171]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 02:17:01 mymachine CRON[25588]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 03:17:01 mymachine CRON[26026]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 03:25:01 mymachine CRON[30320]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
Aug 23 04:17:01 mymachine CRON[26363]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 05:17:01 mymachine CRON[26770]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 06:17:01 mymachine CRON[27168]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 07:17:01 mymachine CRON[27547]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 23 07:30:01 mymachine CRON[2249]: (root) CMD (start -q anacron || :)
Aug 23 07:30:02 mymachine anacron[2252]: Anacron 2.3 started on 2014-08-23
Aug 23 07:30:02 mymachine anacron[2252]: Will run job `cron.daily' in 5 min.
Aug 23 07:30:02 mymachine anacron[2252]: Jobs will be executed sequentially
Aug 23 07:35:02 mymachine anacron[2252]: Job `cron.daily' started

As you can see, at 3:25 it tried to do something. But the cron.daily execution started really at 7:35.

My /etc/crontab is:

# /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 3    * * *   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 )
#

From what I understand, daily scripts are indeed for 3:25.

My /etc/anacrontab is:

# /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

So...does someone know why my cron started to do something at 3:25 but then really start the jobs at 7:35?

Also..as you can see in the log, hourly jobs are being executed at correct time: hour and 17 minutes, which is exactly what I have in /etc/crontab

Finally, from the logs, it seems my daily jobs are being actually run by anacron rather than cron? So cron finds nothing to run (at 3:25) and then anacron runs the jobs at 7:35? If true, how can I fix this?

Thanks in advance,

1
  • 1
    Read the documentation for anacron. You don't need both anacron and cron entries. Chose one or the other but not both.
    – user9517
    Aug 23, 2014 at 16:33

1 Answer 1

2
test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

This runs the test command, and then only runs the ( cd ...) sequence if the test command failed. If anacron is installed, then the test command would succeed, and the rest of the command line wouldn't run. In other words, this line only executes cron.daily if anacron isn't installed.

Meanwhile, anacron is being invoked periodically, and it eventually runs cron.daily based on its own configuration file. It looks like anacron may not be invoked earlier in the day, or else it would have run cron.daily earlier.

If you want the command to run from cron rather than anacron, you could edit their respective configurations, and maybe set anacron to run earlier in the day. Or you could remove anacron entirely if you don't want to use it.

2
  • Hi Kenster, thanks for your answer. In my case, this a server, which is not expected to be down. So...I guess modifying /etc/crontab so that I use cron for daily scricpts seems correct. Or is there any advantage of using anacron that I am not seeing? Thanks! Aug 23, 2014 at 17:02
  • 1
    Anacron is for running jobs on systems that aren't on 24x7, like personal workstations or laptops. If this system is up all the time, you probably don't need anacron. On the other hand, once you start changing vendor-provided aspects of the system, you become responsible for documenting and maintaining the changes. There is some advantage in leaving minor details of the system the way the vendor set them.
    – Kenster
    Aug 23, 2014 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .