Many of us UNIX old-timers are quite accustomed to cronjobs, but MacOSX has a centralized “LaunchDaemon” called launchd — to leverage it to run cronjobs gives an OS-specific, perhaps OS-preferred, method of doing so.
The TL;DR:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>Label</key><string>com.example.rsync.SyncTheRepos</string>
<key>Program</key><string>/usr/bin/rsync</string>
<key>ProgramArguments</key>
<array>
<string>-avr</string>
<string>–delete-after</string>
<string>rsync.example.com::repos</string>
<string>~/Documents/Repos</string>
</array>
<key>EnableGlobbing</key><true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key><integer>3</integer>
<key>Minute</key><integer>14</integer>
</dict>
<key>ProcessType</key><string>Background</string>
</dict>
</plist>
In general, there is a lot of flexibility in setting up a launchd plist — the config info on https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html plus the various examples on the internet should help, but I generally take this example and re-use it.
Once this plist is saved as a local text file in ~/Library/LaunchAgents/
(for example, I’ll save mine as ~/Library/LaunchAgents/rsync-repos.plist
), I activate it using:
launchd load -w ~/Library/LaunchAgents/rsync-repos.plist
If I want to disable the job, I use:
launchd unload -w ~/Library/LaunchAgents/rsync-repos.plist
The files are not modified in either case.
Recent Comments