Open In App

anacron command in linux with examples

anacron command is used to execute commands periodically with a frequency specified in days. Its main advantage over cron is that it can be used on a machine which is not running continuously. In cron if a machine is not running on time of a scheduled job then it will skip it, but anacron is a bit different as it first checks for timestamp of the job then decides whether to run it or not and if its timestamp is >=n(n is defined number of days) then runs it after a specified time delay.

It mainly constitutes of two important Files:



  1. /etc/anacrontab : It contains specifications of job.

    • See line SHELL=/bin/sh. It uses sh not bash you cannot run bash scripts.
    • Table at the last represents different scheduling. The first column is the number of days(n) i.e. period and second is a time delay in minutes.
  2. /var/spool/anacron : This directory is used by Anacron for storing timestamp files. It represents timestamp for different category of jobs i.e. daily, weekly, monthly, etc.

Syntax:



anacron [-s]  [-f]  [-n] [-d] [-q] [-t anacrontab] [-S spooldir] [job]
anacron [-S spooldir] -u [-t anacrontab] [job] ...
 anacron [-V|-h]
 anacron -T [-t anacrontab]

Options:

Note:

Examples:

Note: Here we have used -d option with all commands to display on the screen what is actually happening.

Article Tags :