1

The /etc/crontab on my machine is as follows:

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 )

I have two related questions:

  • Why 17, 25, 47, 52? I get that you might want to stagger the different jobs, but why not stagger them more evenly? Like for instance 0, 15, 30, 45?
  • Why is anacron used for the daily/weekly/monthly commands but not the hourly ones? Are hourly commands more OK to miss? (If I understand correctly, anacron is for if you have an "Every Saturday" command and the computer is down on Saturday, it runs the command on Sunday instead).
k_g
  • 163
  • 1
    “why not stagger them more evenly?” That way would run everything at the same time for some moments, leaving the system completely idle all the rest of the time. It's not very convenient. – Andrea Lazzarotto Apr 17 '17 at 21:52
  • 1
    The point is not to 'stagger' the jobs. On that one day a couple times each year when all the jobs run, the point is to merely to prevent jobs that interfere with each other from running simultaneously. Since user-created cronjobs are likely to use evenly-spaced times, the system jobs try to avoid those, too. – user535733 Apr 18 '17 at 00:01
  • Anacron is not used hourly simply because it doesn't need to be. None of the hourly jobs need to be caught-up if the system is turned off or suspended for, say, 3 hours. – user535733 Apr 18 '17 at 00:09

1 Answers1

3

I don't know the answer for the first question. Here is second,

Cron is designed for machines that are left running continuously. If your machine is turned off when a job falls due, it simply won't be run. To handle this situation better, a new tool called Anacron was written. anacron's mission is to guarantee that those daily, weekly and monthly activities do actually occur, assuming only that the computer was switched on at some point during the day. It does not record hours, minutes or seconds, only days, months, and weeks.

It's conf file is -> /etc/anacrontab

Anacron is run at boot time, via the script /etc/init.d/anacron.

Anacron does not expect the system to be running 24 x 7 like a server.

When you want a background job to be executed automatically on a machine that is not running 24 x 7, you should use anacron.

if you have a backup script scheduled everyday at 11 PM as a regular cron job, and if your laptop is not up at 11 PM, your backup job will not be executed.

However, if you have the same job scheduled in anacron, you can be sure that it will be executed once the laptop come back up.

It is Ideal for desktops and laptops.

enter image description here

luv.preet
  • 5,787