Mmmmmk, so apparently
cron is going the way of the dodo on OS X/Darwin. Best practice is to move your cron jobs to
launchd. Here’s the Apple kb info for timed jobs using
launchd (which includes the notice of deprecation) and here’s a great tutorial on using
My goal was to automagically keep MacPorts up-to-date, ala Ubuntu’s unattended upgrades. Because I’m old, I put
port upgrade outdated &
port uninstall inactive in root’s crontab, but then today I was reading more and decided that I really ought to do it the Mac way since it’ll be upgrade proof.
Introducing portsUpdate! You can download the portsUpdate via git.
portsUpdate is copyleft.
Note: portsUpdate works with OS X 10.11 El Capitan. I am not going to test it with older Mac versions, although if your system runs launchd, you could try it. YMMV, I’m not responsible if you break your system in any case.
portsUpdate is a launchd xml file that runs a bash script once daily to update MacPorts, an associated launchd xml to ensure that the path is correct, and an associated installer.
If you trust me (don’t, why would you), you can just download the installer, open Terminal.app, &…
$ cd yourDownloadsDirectory
$ chmod +x InstallMacPortsUpdater
$ sudo ./InstallMacPortsUpdater
& have a coffee. Your MacPorts will update every morning at 3:30 a.m. & your old packages will be removed every Sunday to keep your system running lean.
If you want to know how to use it and want to read the scripts (or even improve upon them!) please read on along…
In particular, note the policy on timed
launchd jobs and the computer state: if your machine is asleep, it’ll run when it wakes, if it’s off, it’ll run the next time it’s scheduled.
I tend to enable Power Nap, especially on fixed workstations:
System Preferences > Engery Saver > Enable Power Nap
So if you want to inspect it before you install, just:
$ git clone https://github.com/seannyob/portsUpdate
$ cd portsUpdate
Note that there are four files:
And then to install you would just set
Install executable if it isn’t, then run it with
setenv.PATH.plist resolves an issue with
launchd which is that scripts/applications/programs in
/opt/local/bin are not in
com.seannyob.portsUpdate.plist tells launchd where portsUpdate is located & when to run it.
portsUpdate is a bash script that runs updates, upgrades & cleanup of your MacPorts package database, ensuring that you are always up to date on features & any security &/or bug fixes of your critical unixy apps.
Install is the same as
InstallMacPortsUpdater above. It is a bash script that checks to make sure you’ve installed MacPorts, then git, then gits the package, then installs the three other aforementioned files in their appropriate places in the file system, then loads them into
Note in particular that if you wanted to modify the time &/or frequency of updates/upgrades, you could do so in
com.seannyob.portsUpdate.plist and the frequency of uninstall inactive is set for Sundays in
Feel free to peruse them and use or modify them to your liking. If you have comments &/or suggestions, please let me know!