Cron and launchctl on Mac OS X 10.5 Leopard
I was searching for a way to set up a cron job on my Mac, and couldn't find anything that spelled it out exactly how I needed it. http://arunxjacob.wordpress.com/ got me really really close though. I did finally get it working, so I thought I'd explain the crucial parts of my setup.
My goal is to port this cron command to my Mac:
*/5 * * * * wget -O - -q -t 1 http://drupaldev1/cron.php
1. Create a .plist file. A new empty plain text file. I named mine local.drupaldev1.plist
, since this is for a local development site on my computer. I placed it in ~/Library/LaunchAgents/ but you can put it anywhere on your computer.
2. Open that file in a plain text editor and paste in this starter code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>local.drupaldev1</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/wget</string>
<string>http://drupaldev1/cron.php</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>RunAtLoad</key>
<true />
<key>StandardErrorPath</key>
<string>/dev/null</string>
<key>StandardOutPath</key>
<string>/dev/null</string>
</dict>
</plist>
The first string listed under ProgramArguments is the program to execute. All strings that immediately follow it are its arguments.
3. Activate the file by doing this at the command line:
launchctl load /Users/my_username/Library/LaunchAgents/local.drupaldev1.plist
If you need to make changes to it, unload it and reload it.
launchctl unload /Users/my_username/Library/LaunchAgents/local.drupaldev1.plist
launchctl load /Users/my_username/Library/LaunchAgents/local.drupaldev1.plist
4. To make it load automatically when you startup your mac, create this file: ~/.launchd.conf
and paste in the line above, minus launchctl:
load /Users/my_username/Library/LaunchAgents/local.drupaldev1.plist
5. The sites that I found useful...
http://arunxjacob.wordpress.com/2008/08/28/mac-launchd-and-launchctl-the...
http://www.wooblelab.com/command/show/106-scheduled-jobs-with-launch-dae...
http://en.wikipedia.org/wiki/Launchd
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/...
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/...
http://developer.apple.com/macosx/launchd.html