Chapter 35.
Automated Tasks
In Linux, tasks can be configured to run automatically within a specified period of time, on a specified
date, or when the system load average is below a specified number. Red Hat Enterprise Linux is
pre-configured to run important system tasks to keep the system updated. For example, the slocate
database used by the locate command is updated daily. A system administrator can use automated
tasks to perform periodic backups, monitor the system, run custom scripts, and more.
Red Hat Enterprise Linux comes with several automated tasks utilities: cron, at, and batch.
35.1. Cron
Cron is a daemon that can be used to schedule the execution of recurring tasks according to a
combination of the time, day of the month, month, day of the week, and week.
Cron assumes that the system is on continuously. If the system is not on when a task is scheduled, it
Section 35.2, "At and
Batch".
is not executed. To schedule one-time tasks, refer to
To use the cron service, the vixie-cron RPM package must be installed and the crond service
must be running. To determine if the package is installed, use the rpm -q vixie-cron command.
To determine if the service is running, use the command /sbin/service crond status.
35.1.1. Configuring Cron Tasks
The main configuration file for cron, /etc/crontab, contains the following lines:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
The first four lines are variables used to configure the environment in which the cron tasks are run.
The SHELL variable tells the system which shell environment to use (in this example the bash shell),
while the PATH variable defines the path used to execute commands. The output of the cron tasks are
emailed to the username defined with the MAILTO variable. If the MAILTO variable is defined as an
empty string (MAILTO=""), email is not sent. The HOME variable can be used to set the home directory
to use when executing commands or scripts.
Each line in the /etc/crontab file represents a task and has the following format:
minute
hour
day
month
dayofweek
command
• minute — any integer from 0 to 59
• hour — any integer from 0 to 23
• day — any integer from 1 to 31 (must be a valid day if a month is specified)
505
Need help?
Do you have a question about the ENTERPRISE LINUX 5 - DEPLOYMENT and is the answer not in the manual?
Questions and answers