Red Hat ENTERPRISE LINUX 5 - DEPLOYMENT Deployment Manual page 532

Hide thumbs Also See for ENTERPRISE LINUX 5 - DEPLOYMENT:
Table of Contents

Advertisement

Chapter 35. Automated Tasks
• month — any integer from 1 to 12 (or the short name of the month such as jan or feb)
• dayofweek — any integer from 0 to 7, where 0 or 7 represents Sunday (or the short name of the
week such as sun or mon)
• command — the command to execute (the command can either be a command such as ls /proc
>> /tmp/proc or the command to execute a custom script)
For any of the above values, an asterisk (*) can be used to specify all valid values. For example, an
asterisk for the month value means execute the command every month within the constraints of the
other values.
A hyphen (-) between integers specifies a range of integers. For example, 1-4 means the integers 1,
2, 3, and 4.
A list of values separated by commas (,) specifies a list. For example, 3, 4, 6, 8 indicates those
four specific integers.
The forward slash (/) can be used to specify step values. The value of an integer can be skipped within
a range by following the range with /<integer>. For example, 0-59/2 can be used to define every
other minute in the minute field. Step values can also be used with an asterisk. For instance, the value
*/3 can be used in the month field to run the task every third month.
Any lines that begin with a hash mark (#) are comments and are not processed.
As shown in the /etc/crontab file, the run-parts script executes the scripts in the /etc/
cron.hourly/, /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly/
directories on an hourly, daily, weekly, or monthly basis respectively. The files in these directories
should be shell scripts.
If a cron task is required to be executed on a schedule other than hourly, daily, weekly, or monthly, it
can be added to the /etc/cron.d/ directory. All files in this directory use the same syntax as /etc/
Example 35.1, "Crontab Examples"
crontab. Refer to
# record the memory usage of the system every monday
# at 3:30AM in the file /tmp/meminfo
30 3 * * mon cat /proc/meminfo >> /tmp/meminfo
# run custom script the first day of every month at 4:10AM
10 4 1 * * /root/scripts/backup.sh
Example 35.1. Crontab Examples
Users other than root can configure cron tasks by using the crontab utility. All user-defined crontabs
are stored in the /var/spool/cron/ directory and are executed using the usernames of the users
that created them. To create a crontab as a user, login as that user and type the command crontab
-e to edit the user's crontab using the editor specified by the VISUAL or EDITOR environment
variable. The file uses the same format as /etc/crontab. When the changes to the crontab
are saved, the crontab is stored according to username and written to the file /var/spool/
cron/username.
The cron daemon checks the /etc/crontab file, the /etc/cron.d/ directory, and the /var/
spool/cron/ directory every minute for any changes. If any changes are found, they are loaded into
memory. Thus, the daemon does not need to be restarted if a crontab file is changed.
506
for examples.

Advertisement

Table of Contents
loading

Table of Contents