Using the Periodic Task Scheduler


The periodic command is like a souped-up version of cron. It's designed to provide a framework for executing whole directories full of shell scripts at regular intervals specified in a crontab file. In FreeBSD's default configuration, periodic is used for many housekeeping functions, controlled by a directory structure full of shell scripts located in /etc.

If you examine /etc/crontab, you will see three references to the periodic command:

# do daily/weekly/monthly maintenance 1       3       *       *       *           root periodic daily 15      4       *       *       6           root periodic weekly 30      5       1       *       *           root periodic monthly


The periodic command is invoked three times, with three different arguments: daily, weekly, and monthly. These arguments correspond to three different subdirectories of /etc/periodic. Each subdirectory, named in accordance with the three arguments, contains a number of shell programs, each of which executes a specific taskin this case, a maintenance task that the system carries out either daily, weekly, or monthly, at the specified times in /etc/crontab. In /etc/periodic/daily, for example, you will find such scripts as 100.clean-disks, 200.backup-passwd, and 999.local. Simply by existing in the subdirectories of /etc/periodic, these scripts will be run when periodic is executed with the name of their directory as an argument.

Scripts in the periodic directories are traditionally prefixed with numbers; because periodic executes scripts in lexicographical order, using numbers provides an easy way to define the order in which the scripts should be run. For example, 999.local is always the last script to run in /etc/periodic/daily.

The output of these periodic runs is gathered into a mail message and sent to root (by default). This is the origin of the daily system summary messages that your FreeBSD machine sends you each night shortly after 3:00 a.m. Reading through the periodic source directories, you will be able to see what the system is doing to generate all the disk status, user login accounting, news, UUCP, mail, and other pieces of status it throws at you every day, week, and month.

Each script in the periodic directories has individual behaviors that are defined in /etc/defaults/periodic.conf. You can examine that file to see how each script is treated, and you can override those settings by creating an /etc/periodic.conf file, which operates the same way that /etc/rc.conf does, masking the defaults set in the corresponding file in the defaults directory. You can use this technique to send the script output to a different user or to a log file, instead of to root, for instance. You can also turn on or off the output reporting for individual scripts as well as adjust many other scriptspecific variables that control how the scripts themselves operate.

Note

The /etc/periodic/security directory is special; it contains scripts that specifically address security-related tasks, such as looking for new setuid programs, accounts without passwords, and kernel firewall messages. The scripts in this directory are run in a separate process and handled differently from the normal daily maintenance scripts, in order to minimize the risk of sensitive information being gleaned by an eavesdropper. This behavior can be modified by overriding the settings in /etc/defaults/periodic.conf using /etc/periodic.conf.


You can add your own scripts to the periodic directories if you want. However, as you have seen before, it's considered safer and better form to avoid editing the global files in /etc when an alternative "local" version is available. In this case, /usr/local/etc/periodic is the location for any daily, weekly, or monthly scripts you might want to add. The scripts are executed at the same time that /etc/crontab runs the global periodic scripts. Immediately after finishing the scripts in /etc/periodic/daily, for example, periodic will run whatever it finds in /usr/local/etc/periodic/daily, in lexicographical order as with the global location.

Adding scripts to the periodic directories is a good way to schedule specific tasks to be performed on an ongoing basisfor example, a script that cleans up a temporary directory, a database backup process, or a CVSup process that synchronizes your FreeBSD sources (you learn more about synchronizing FreeBSD sources in Chapter 19, "Keeping Up to Date with FreeBSD"). It's far neater and more formal to use the periodic structure to handle these tasks than putting them all in a huge crontab file!




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net