1

I've got a pretty good handle on how cron/anacron work on linux. My question is this:

  1. anacron runs at login, and checks if it's been more than a day since the scripts in /etc/cron.daily have run
  2. anacron runs scripts in /etc/cron.daily, and updates the timestamp in /var/spool/anacron/cron.daily
  3. anacron exits
  4. computer stays on for more than 24 hours
  5. cron runs and detects a time match for cron.daily
  6. cron does nothing since test -x anacrontab" == True

If my computer runs for more than 24 hours, how does cron run the scripts in cron.daily (This is a Debian based distro)?

the default /etc/crontab (which is running every minute) tests for the presence (or more precisely, the -x bit) of /usr/bin/anacron, and ignores the /etc/cron.daily folder if it finds it, but it doesn't seem to restart anacron to do the work.

EDIT:

So cron DOES start anacron from the /etc/cron.d folder, but only if the computer is on and logged in at 7:30 am every day. After doing a little spreadsheet kung-fu, I've come to the conclusion that the scripts in /etc/cron.daily will run anywhere between 1 minute and 31.5 hours apart.

Ex:

Scenario 1:

  • log in at 11:59 pm on 5/23/2021
  • assuming the anacron timestamp for /etc/cron.daily is older than 5/23/2021, anacron runs all the scrips in /etc/cron.daily and updates the timestamp to 5/23/2021
  • log out
  • log back in at 12:00 am on 5/24/2021
  • anacron sees that the last run was 5/23/2021, and it is now 5/24/2021, so anacron runs all the scripts in /etc/cron.daily
  • elapsed time between runs: 1 minute

Scenario 2:

  • log in at 12:00 am on 5/23/2021
  • assuming the anacron timestamp for /etc/cron.daily is older than 5/23/2021, anacron runs all the scrips in /etc/cron.daily and updates the timestamp to 5/23/2021
  • computer stays on and logged in until 7:30 am on 5/23/2021
  • cron runs anacron from its crontab file in /etc/cron.d
  • since the timestamp is 5/23/2021, nothing happens
  • computer stays on and logged in until 7:30 am on 5/24/2021
  • cron runs anacron from its crontab file in /etc/cron.d
  • anacron sees that the last run was 5/23/2021, and it is now 5/24/2021, so anacron runs all the scripts in /etc/cron.daily
  • elapsed time between runs: 31.5 hours
2
  • Do you have /etc/cron.d/anacron and /etc/cron.daily/0anacron? That will run anacron's daily tab from a daily cron job (anacron -u cron.daily). I'm not sure what you mean by your sixth point.
    – Kusalananda
    May 26 at 19:31
  • anacron -u only updates the timestamps, but DOES NOT start anacron. The 0anacron just calls anacron -u. /etc/cron.d/anacron only starts anacron if the comnputer is on at 7:30 am. May 27 at 1:48
0

All the system /etc/cron.daily, /etc/cron.weekly etc files include an entry to run anacron which in turn includes an entry to run cron. /etc/crontab includes entries for run-parts so that anacron is either run by run-parts or by cron.

Another file to consider is /etc/anacrontab which can override some of the effects of /etc/crontab

An important system cron related file is /etc/cron.daily/logrotate which is a script used to initiate log rotation processing.

Ordinary user crontabs are executed independently of system cronjobs.

Note that /etc/crontab is not running every minute - activity is determined by the various crontab specifications.

1
  • 1
    /etc/cron.{daily, weekly, monthly} do include 0anacron, which updates the timestamps, but DO NOT start anacron. /etc/cron.d will start anacron, but only at 7:30 am. May 27 at 1:26

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.