UNIX includes a program named 'cron' to handle the execution of tasks on a specified schedule, regardless of whether the user is logged in or not. Cron does this through a series of simple text files known as 'crontabs' which control the scheduling of jobs.
The cron daemon is used by the system for scheduled daily, weekly, and monthly maintenance, and can be used by users to run various programs at set intervals, such as to handle my site backup program as described elsewhere on this site.
Read the rest of this article if you'd like a simple overview of what cron is and how it can be used.
The system cron tasks are stored in /etc/crontab. You can "cat" this file to get an example of what a crontab looks like:
user% cat /etc/crontab[NOTE: There are TABS between the items, so don't copy/paste anything you see here; type it with tabs between fields!]
# $NetBSD: crontab,v 1.13 1997/10/26 13:36:31 lukem Exp $
#
# /etc/crontab - root's crontab
#
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#min hour mday month wday user command
*/10 * * * * root /usr/libexec/atrun
# do daily/weekly/monthly maintenance
15 3 * * * root sh /etc/daily...
30 4 * * 6 root sh /etc/weekly...
30 5 1 * * root sh /etc/monthly...
#min hour mday month wday commandThe 'sh getmybackup' runs my backup download shell script (see the related article on automated backups), and the time section is set to run it twice a day - at 2:25am, and 2:25pm (1425 in military time). Once the edited file has been saved, the final step is to tell the 'cron' program to schedule the task:
25 2,14 * * * sh path/to/getmybackup.sh
crontab mycrontabThat's all there is to it; the task is scheduled and will be executed twice a day at the specified time, as long as my machine is powered on. You can see a list of currently scheduled tasks by typing "crontab -l" at the command prompt, and you can cancel a crontab with "crontab -r".
Mac OS X Hints
http://hints.macworld.com/article.php?story=2001020700163714