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 |
period — frequency (in
days) to execute the command
delay — delay time in
minutes
job-identifier —
description of the task, used in Anacron messages and as the name
of the job's timestamp file, can contain any non-blank characters
(except slashes)
command — command to
execute
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:
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.