22.2. Scheduling a Recurring Asynchronous Job Using Anacron
cron, is a service that enables you to schedule running a task, often called a job, at regular times. However,
cronin two ways:
- If the system is not running at the scheduled time, an
anacronjob is postponed until the system is running;
anacronjob can run once per day at most.
anacrontabfiles. These files are then read by the
crondservice, which executes the jobs.
22.2.1. Prerequisites for Anacrob Jobs
- Verify that you have the cronie-anacron package installed:
rpm -q cronie-anacronThe cronie-anacron is likely to be installed already, because it is a sub-package of the cronie package. If it is not installed, use this command:
yum install cronie-anacron
crondservice is enabled - made to start automatically at boot time - upon installation. If you disabled the service, enable it:
systemctl enable crond.service
- Start the
crondservice for the current session:
systemctl start crond.service
- (optional) Configure anacron. For example, you can change:
See the anacrontab(5) manual page for information on configuring
- shell to be used when executing jobs
- mail addressee if a job sends emails.
22.2.2. Scheduling an Anacron Job
Scheduling an anacron Job as
rootuser uses the anacron table in
/etc/anacrontab. Use the following procedure to schedule a job as
Procedure 22.1. Scheduling an anacron Job as
Combine the chosen values into the job specification. Here is an example specification:
- Frequency of executing the job. For example, use
1to specify every day or
3to specify once in 3 days.
- The delay of executing the job. For example, use
0to specify no delay or
60to specify 1 hour of delay.
- The job identifier, which will be used for logging. For example, use
my.anacron.jobto log the job with the
- The command to execute. For example, use
3 60 cron.daily /usr/local/bin/my-script.sh
- Add the resulting line to
/etc/anacrontabfile. For full reference on how to specify a job, see the anacrontab(5) manual page.