Show Table of Contents
Scheduling an anacron Job as
23.2. Scheduling a Recurring Asynchronous Job Using Anacron
Anacron, like cron, is a service that enables you to schedule running a task, often called a job, at regular times. However, anacron differs from cron in two ways:
- If the system is not running at the scheduled time, an
anacronjob is postponed until the system is running; - An
anacronjob can run once per day at most.
Users specify anacron jobs in anacron table files, also called
anacrontab files. These files are then read by the crond service, which executes the jobs.
23.2.1. Prerequisites for Anacrob Jobs
Before scheduling an
anacron job:
- 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 - The
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:
- shell to be used when executing jobs
- the
PATHenvironment variable - mail addressee if a job sends emails.
See the anacrontab(5) manual page for information on configuringanacron.
23.2.2. Scheduling an Anacron Job
Scheduling an anacron Job as root User
The
root user uses the anacron table in /etc/anacrontab. Use the following procedure to schedule a job as root.
Procedure 23.1. Scheduling an anacron Job as root User
- Choose:
- Frequency of executing the job. For example, use
1to specify every day or3to specify once in 3 days. - The delay of executing the job. For example, use
0to specify no delay or60to specify 1 hour of delay. - The job identifier, which will be used for logging. For example, use
my.anacron.jobto log the job with themy.anacron.jobstring. - The command to execute. For example, use
/usr/local/bin/my-script.sh
Combine the chosen values into the job specification. Here is an example specification:3 60 cron.daily /usr/local/bin/my-script.sh
- Add the resulting line to
/etc/anacrontab.
The job will now run as scheduled.
For simple job examples, see the
/etc/anacrontab file. For full reference on how to specify a job, see the anacrontab(5) manual page.
Scheduling Hourly, Daily, Weekly, and Monthly Jobs
You can schedule daily, weekly, and monthly jobs with anacron. See the section called “Scheduling Hourly, Daily, Weekly, and Monthly Jobs”.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.