Cron Job

I'm trying to setup a script to run every half an hour or so and was wondering if there was any documentation on setting up a cron job with Mac OS X (10.5). Or is there anther easy way to do it? It's just a shell script that needs to be run.

Cheers.

Mac OS X (10.5.3)

Posted on Jun 18, 2008 2:02 AM

Reply
3 replies

Jun 18, 2008 2:26 AM in response to peter.f

Apple's recommended why is launchd. Search for Lingon or Launchd Editor for some GUI tools to help you compose the schedule.

However, cron still works in Leopard and I agree that a simple cron entry is far easier than dealing with launchd, especially since I am put off by some of launchd's earlier (Tiger) limitations.

Apple removed all the cron templates in Leopard but the cron scheduler is still there and works fine. To get cron going in OS X, you need to either create a file called /etc/crontab or create user cron tabs in /var/cron/tabs. Since you are likely the only user and you need only one entry, simply use /etc/crontab.

The syntax is simple, each value separated by a tab:
30 18 * * * peterf /path/to/script

This means:
30 is the minute (0 - 59)
18 is the hour (0 - 23)
* is the day of the month (1 - 31)
* is the month of the year (1 - 12)
* is the day of the week (0 - 6, 0 being Sunday)
peterf is the user that you want to run the script
/path/to/script is the full UNIX path to the script, case is sensitive

That is pretty much it. The file must be a plain text file with UNIX line breaks, so use a command line editor like vi, pico, or emacs to create. Once the crontab file is present cron should kick off and start working. If it does not, then you may need to use launchd to start cron. This can be done with:

sudo launchctl -w load /System/Library/LaunchDaemons/com.vix.cron.plist

You likely will not need that however.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Cron Job

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.