Anacron

Anacron is designed for tasks that need to run periodically (daily, weekly, monthly) on systems that are not continuously powered on. If a scheduled cron task is missed because the system is off, anacron will run the task once the system is available.

On many systems, anacron is pre-installed. If not, install it with:

$ sudo apt install anacron
Anacron's configuration is in the /etc/anacrontab file, which includes helpful comments and examples. Here’s an excerpt:

$ sudo vim /etc/anacrontab
# See anacron(8) and anacrontab(5) for details.
# These entries replace cron's job 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

The syntax in the anacrontab file consists of four fields:

  1. The period in days (e.g., 1 for daily, 7 for weekly).
  2. A delay (in minutes) after system startup.
  3. A unique job identifier.
  4. The command to execute.

For example, to run a job every three days with a 10-minute delay:

3 10 test_job /usr/bin/touch /root/anacron_created_this

Other examples include:

7 10 test_job /usr/bin/touch /root/anacron_created_this
@monthly 10 test_job /usr/bin/touch /root/anacron_created_this

After editing, verify your anacrontab syntax with:

$ anacron -T
anacron: /etc/anacrontab: Unknown named period on line 13, skipping

If no errors are reported, your anacron entries are correctly formatted.

Consult the anacron man pages for more info.