28.2. Anacron

Anacron is a task scheduler similar to cron except that it does not require the system to run continuously. It can be used to run the daily, weekly, and monthly jobs usually run by cron.

To use the Anacron service, you must have the anacron RPM package installed and the anacron service must be running. To determine if the package is installed, use the rpm -q anacron command. To determine if the service is running, use the command /sbin/service anacron status.

28.2.1. Configuring Anacron Tasks

Anacron tasks are listed in the configuration file /etc/anacrontab. Each line in the configuration file corresponds to a task and has the format:

period   delay   job-identifier  command

For each task, Anacron determines if the task has been executed within the period specified in the period field of the configuration file. If it has not been executed within the given period, Anacron executes the command specified in the command field after waiting the number of minutes specified in the delay field.

After the task is completed, Anacron records the date in a timestamp file in the /var/spool/anacron directory. Only the date is used (not the time), and the value of the job-identifier is used as the filename for the timestamp file.

Environment variables such as SHELL and PATH can be defined at the top of /etc/anacrontab as with the cron configuration file.

The default configuration file looks similar to the following:

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# These entries are useful for a Red Hat Linux system.
1       5       cron.daily              run-parts /etc/cron.daily
7       10      cron.weekly             run-parts /etc/cron.weekly
30      15      cron.monthly            run-parts /etc/cron.monthly

Figure 28-1. Default anacrontab

As you can see in Figure 28-1, anacron for Red Hat Linux is configured to make sure the daily, weekly, and monthly cron tasks are run.

28.2.2. Starting and Stopping the Service

To start the anacron service, use the command /sbin/service anacron start. To stop the service, use the command /sbin/service anacron stop. It is recommended that you start the service at boot time. Refer to Chapter 14 Controlling Access to Services for details on starting the anacron service automatically at boot time.