Run a shell script at specific times

To schedule a shell script to run at specific times, use either launchd or cron.

Schedule tasks with launchd

Use cron to schedule a task

The cron daemon executes scheduled commands defined in crontab files. The cron daemon searches the /usr/lib/cron/tabs/ folder for crontab files named after accounts in /etc/passwd, and loads the files into memory. The cron daemon also searches the /etc/crontab/ folder for crontab files, which are in a different format. cron then cycles every minute, examining stored crontab files 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 file or to the user named in the optional MAILTO environment variable in the crontab file.

You use the crontab tool to install, uninstall, or list the tables used to drive the cron daemon. Users can have their own crontab file.