Online Book Reader

Home Category

UNIX System Administration Handbook - Evi Nemeth [102]

By Root 3041 0
not to the target numbers themselves. If you add or remove a disk, all the drive letters change!

15. Note that the FreeBSD terminology is the opposite of that used by Solaris on Intel systems. In Solaris, volumes in the fdisk label are called partitions, and volumes in the Solaris label are called slices.

9 Periodic Processes

The key to staying in control of your system is to automate as many tasks as possible. For example, an adduser program can add new users faster than you can, with a smaller chance of making mistakes. Almost any task can be encoded in a shell, Perl, or expect script.

It’s often useful to have a script or command executed without any human intervention. For example, you might want to have a script verify (say, every half-hour) that your network routers and bridges are working correctly and have it send you email when problems are discovered.1

1Many sites go further than this and dial a pager with a modem, so that an administrator can be summoned as soon as a problem is detected.

9.1 CRON: SCHEDULE COMMANDS


Under UNIX, periodic execution is handled by the cron daemon. cron starts when the system boots and remains running as long as the system is up. cron reads one or more configuration files containing lists of command lines and times at which they are to be invoked. The command lines are executed by sh, so almost anything you can do by hand from the shell can also be done via cron.2

A cron configuration file is called a “crontab,” short for “cron table.” All crontab files are stored in a single system directory, where cron knows to look for them. The crontab command transfers crontab files to and from this directory.

Typically, there is (at most) one crontab file per user: one for root, one for jsmith, and so on. Crontab files are named with the login names of the users they belong to, and cron uses these filenames to figure out which UID to use when running the commands that each file contains.

Old versions of cron scan their crontabs periodically and execute all commands that should have been run since the last scan. Modern versions parse the crontabs, figure out which of the listed commands needs to be run soonest, and go to sleep until the command’s execution time has arrived.

On some systems, sending cron a hangup signal forces it to reread the crontabs. However, it is usually not necessary to send the signal by hand because crontab automatically tells cron to update itself whenever it changes a configuration file.

cron normally does its work silently, but some versions can keep a log file (usually /var/cron/log or /var/adm/cron/log) that lists the commands that were executed and the times at which they ran. On some systems, creating the log file enables logging, and removing the log file turns logging off. On other systems, the log is turned on or off in a configuration file. Yet another variation is for cron to use syslog. The log file grows quickly and is rarely useful; leave logging turned off unless you’re debugging a specific problem.

See Chapter 11 for more information about syslog.

Most crons do not compensate for commands that are missed while the system is down. In addition, some versions of cron do not understand daylight saving time, causing commands to be skipped or run twice when time changes occur. If you use cron for time-sensitive tasks (such as accounting), keep an eye open for these situations. You can forestall potential problems by avoiding times of day that may be affected by transitions (times between 1:00 and 3:00 a.m. in the U.S., for example).

9.2 THE FORMAT OF CRONTAB FILES


All the crontab files on a system share a common format. Comments are introduced with a pound sign (#) in the first column of a line. Each noncomment line contains six fields and represents one command:

minute hour day month weekday command

The first five fields are separated by whitespace, but within the command field whitespace is taken literally.

minute, hour, day, month, and weekday give information about the times at which the command should

Return Main Page Previous Page Next Page

®Online Book Reader