Cron Tasks

Through the Unix cron utilities, you can have your Macintosh run scripts and other programs at scheduled times or regular intervals. While this is a pretty neat feature that offers convenience to users and crucial maintenance-program scheduling for system administrators, Mac OS X does not ship with any friendly, GUI frontend to the cron utilities. That said, if you can use a text editor (such as any of those described in Chapter 17), then you can set up cron tasks for yourself or (if you have the right credentials) the whole machine.

Cron works courtesy of a clock-watching daemon named crond . When this loads, it reads all of the cron tables defined in some standard filesystem locations, which contain entries representing lists of times or repeating intervals, with a Darwin command to execute for each entry. On Mac OS X, these tables exist in two locations:

/etc/crontab

This is the cron table for the whole system. Each entry in this table represents a command that root will run at the given time. The file is world-readable, but only root may edit it.

/var/cron/tabs/

This directory contains one file for each user on the machine who uses the cron system. You actually don’t interact directly with these files (whose permissions prevent it anyway); you must use the crontab -e command to edit your own file. You cannot read or change other users’ cron tables.

The cron tables’ format is tricky and hard to remember (unless you’re a system administrator who must update ...

Get Mac OS X in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.