4

I want to setup a cron job to download up-to-date package only at night. But I found that the cron.daily jobs will be run by anacron if it's installed, so if my computer fails to wake-up at night to do the job, it will run the next time I turn it on.

How configure my system to run /etc/cron.daily/apt exclusively with cron (i.e. at and only at the specified time)?

This is my /etc/crontab

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

1 Answer 1

4

Move your script out of /etc/cron.daily and add an entry for it directly in /etc/crontab. For example, you could move it to /usr/local/sbin/cron-apt and then add this entry to /etc/crontab:

0 5 * * * root /usr/local/sbin/cron-apt

This will give you fine control of the exact timing of your job as well. The command man 5 crontab will give you more information on the crontab format.

3
  • /etc/cron.d exists... May 8, 2017 at 6:46
  • According to cron(8): "In general, the system administrator should not use /etc/cron.d/, but use the standard system crontab /etc/crontab". May 8, 2017 at 13:54
  • I'd like to know the rationale for this, because it doesn't make much or any sense. So, I ignore it (and it says "should" anyway). May 9, 2017 at 14:24

You must log in to answer this question.

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