437 439




Using Linux:Managing Scheduling Services






-->















Previous
Table of Contents
Next




Command Settings
Command settings use a standard format: Each line starts with five time/date fields. If this is the system crontab, the next field is the username associated with the entry. Following this entry is the command to be executed. The command is executed only when the current date and time meet all five of the time/date field criteria.
Table 26.3 shows the available time/date fields and the ranges of values for each field. A time/date field can contain an asterisk instead of a number or a name; an asterisk indicates that any valid value should be matched.

Field
Allowable Values

minute
0–59

hour
0–23

day
0–31

month
0–12 (alternatively, three-letter, not case sensitive abbreviations of names can be used)

day of the week
0–7 (with 0 and 7 being Sunday; alternatively, three-letter, not case sensitive abbreviations of names can be used)




Using ranges to specify starting times
Ranges can be specified through the use of a hypen. A value of 1-5 indicates that this field is valid for numbers 1 through 5. If you use a name instead of a number, you cannot specify a range.



Using step values to specify starting times
Step values can be used in conjunction with ranges. To specify a step value, follow the range with a forward slash (/) and a number. The number specified is the step value. For example, the following specifies that every third value (in this case, 2, 5, 8, and 11) should be matched:
Listing 26.2 shows the default /etc/crontab that comes with Red Hat Linux version 5.0.


0-12/3


Step values can also be used with asterisks. The value */3 in the hour field would match every third hour (0, 3, 6, 9, 12, 15, 18, and 21).


Listing 26.2 An example of a crontab file


SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 1 * * * root run-parts /etc/cron.daily
02 2 * * 0 root run-parts /etc/cron.weekly
02 3 1 * * root run-parts /etc/cron.monthly


Notice that this crontab actually calls four different crontabs:

•  One associated with hourly events
•  One associated with daily events
•  One associated with weekly events
•  One associated with monthly events

If you are using a system that switches between Linux and another operating system, such as Windows 95, you might want to kick off some of these cron jobs yourself (if, for example, their scheduled time lapsed while you were in another operating system). Remember: The system does not go back and “pick up” cron jobs; it executes them only if the current date/time matches the entry.


Using lists to specify starting times
Lists are also acceptable; each item in a list is separated by a comma. It is common to use lists in conjunction with ranges, like so:Noyr


1-15,31-45


This example matches all numbers from 1 through 15 and from 31 through 45. If you use a name instead of a number, you cannot specify a list.


Allowing and Preventing Access to the crontab Service

Two files enable root to allow or deny crontab service to users:

•  /etc/cron.allow—This file does not exist by default; you must create it. Any entries you place in this file override entries placed in /etc/cron.deny. If the /etc/cron.allow file exists, only those users specified in that file can use the crontab service.
•  /etc/cron.deny—This file exists by default. In it, you enter the usernames of users who are not allowed to use the crontab service.

It is important that only root be allowed to edit or add these files to the system.

If a user attempts to use cron (crontab -e), but his or her user name has been placed in the /etc/cron.deny file, the following error occurs:n


You (account name) are not allowed to use this program
(crontab).
See crontab(1) for more information.




Specifying a day
The day that a command runs is specified by two fields; day of the week and day. The command runs if either of these is true. For example, the following entry specifies that the command be executed at 5:00 p.m. on the 1st and 15th of the month, and on every Friday:


0 17 1,15 *, 5




Configuring the at Command Service

crontab is great for processes that must be run on a regular schedule, but is a poor tool for something you want to run only once. The at tool enables you to specify a command to run at a certain time; the time can be the current time or it can be a specified time in the future.
To go along with the at command is the batch command, which executes commands when system load levels permit—that is, when the load average (measured by /proc/loadavg) drops below 1.5 or some other value specified at the invocation of atrun.



Previous
Table of Contents
Next














Wyszukiwarka