Specifications

Chapter 3 Scripting the Command Line 25
Note: In earlier versions of Mac OS X and Mac OS X Server, system administrators used
the watchdog daemon to monitor critical services or modied the rc scripts. These are
no longer supported and should be replaced with calls using launchd.
In earlier versions of Mac OS X and Mac OS X Server, system administrators used the
watchdog daemon to monitor critical services or modied the rc scripts. These are no
longer supported and should be replaced with calls using launchd.
For more information about launchd, see the launchd and launchctl man pages. Also
see Technical Note TN2083: Daemons and Agents on the Apple Developer Connection.
Scheduling a Shell Script to Run at Specic Times
To schedule a shell script to run at predened times, use either launchd or the cron
tool. cron is a daemon that executes scheduled commands dened in crontab les.
Using cron to schedule a task
The cron tool searches the /var/cron/tabs/ folder for crontab les named after
accounts in /etc/passwd, and loads the les into memory. The cron tool also searches
for crontab les in the /etc/crontab/ folder, which are in a dierent format. cron then
cycles every minute, examining stored crontab les and checking each command to
see if it should be run in the current minute.
When commands execute, output is mailed to the owner of the crontab le or to the
user named in the optional MAILTO environment variable in the crontab le.
If you modify a crontab le, you must restart cron.
You use crontab to install, deinstall, or list the tables used to drive the cron daemon.
Users can have their own crontab le.
To congure your crontab le, use the crontab -e command. This displays an empty
crontab le.
Heres an example of a congured crontab le:
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#min hour mday month wday command
30 18 * * 1-5 diskutil repairPermissions /Volumes/MacHD
50 23 * * 0 diskutil repairVolume /Volumes/MacHD