BSD DevCenter
oreilly.comSafari Books Online.Conferences.


FreeBSD Basics

Understanding the Automatons


Last year, we took a look at the cron utility in Getting Cron To Do Our Bidding. In the next two articles, I'd like to take a closer look at the actual periodic scripts that cron calls to be executed on a daily, weekly, and monthly basis.

It's always a good idea to be aware of what scripts are running on your computer. Scripts, after all, do stuff that make them a double-edged sword. On the plus side, they can keep you posted on the overall health of your computer and take care of routine housekeeping tasks for you. With the built-in scripts, you don't have to know how to write a shell script in order to perform routine tasks as your FreeBSD system comes with many pre-made scripts that are automatically run for you. On the negative side, any script can be vulnerable to exploits by malicious users. Just as you shouldn't run services on your computer that you don't need, you should only run the scripts that are useful to you and disable the ones you don't need.

The scripts themselves are found in /etc/periodic and are placed in the appropriate subdirectory depending on whether they will be run daily, weekly, or monthly:

ls -F /etc/periodic
./		monthly/
../		weekly/

Each script begins with a number to indicate the order in which the scripts in that directory will be run. That is, a script beginning with the number "120" will run before the script beginning with the number "300". Also, these scripts are executable files as indicated by the * in the output of ls -F:

ls -F /etc/periodic/weekly
./			320.whatis*
../			330.catman*
120.clean-kvmdb*	340.noid*
300.uucp*		400.status-pkg*
310.locate*		999.local*

Finally, these are Bourne shell scripts (that is, they all begin with the line #!/bin/sh) meaning you can test the output of any of these scripts by running it with sh like so:

cd /etc/periodic/daily
sh 430.status-rwho

Local system status:
 8:25AM up 19 days, 21:34, 7 users, load averages: 0.41, 0.38, 0.29

You may remember that cron uses the system crontab file to determine when the scripts in each directory are to be run. I'll show the relevant output here:

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

That is, cron is told to call a program named periodic to run the desired daily scripts every morning at 3:01, the desired weekly scripts every Saturday morning at 4:15, and the desired monthly scripts at 5:30 in the morning on the first day of each month. The periodic program has its own separate configuration file called periodic.conf which is used to specify which of the daily, weekly, and monthly scripts you want to be included in the run, and which you wish to disable.

Your FreeBSD system comes with a default periodic.conf file; let's take a look at the top portion of that file:

head -20 /etc/defaults/periodic.conf
# This is defaults/periodic.conf - a file full 
# of useful variables that you can set to change 
# the default behaviour of periodic jobs on your
# system.  You should not edit this file!  Put any 
# overrides into one of the $periodic_conf_files 
# instead and you will be able to update these defaults
# later without spamming your local configuration 
# information.
# The $periodic_conf_files files should only contain 
# values which override values set in this file.  This 
# eases the upgrade path when defaults are changed and 
# new features are added.
# $FreeBSD: src/etc/defaults/periodic.conf,v 
#   2001/07/28 11:44:22 brian Exp $
# What files override these defaults ?
periodic_conf_files="/etc/periodic.conf /etc/periodic.conf.local"
# periodic script dirs
local_periodic="/usr/local/etc/periodic /usr/X11R6/etc/periodic"
This file makes it pretty clear that you should not make any changes to it and offers two locations to store your own customized version of periodic.conf. If you try to find the files that override the defaults, you'll see that they don't exist as it is up to you to create them:
more /etc/periodic.conf
/etc/periodic.conf: No such file or directory
more /etc/periodic.conf.local
/etc/periodic.conf.local: No such file or directory

Before you start making your customized file, it is a good idea to know what each script does so you can decide whether or not you want it to be executed by the periodic program.

Pages: 1, 2, 3

Next Pagearrow

Sponsored by: