how to update homebrew with Cron on Mac os
Cron doesn't have your PATH defined, make sure you always call commands with the full path, which is probably /usr/local/bin/brew update
This is considered good practice to keep unwanted/unexpected commands from running. If someone put a malicious script called 'brew' somewhere else in your path, but before /usr/local/bin, it would get called instead.
A cronjob is a good option, but I didn't want it to happen automatically. I found a script that will notify you if a new version of a formula installed on your Mac is available.
I extended the script to not show pinned formulae in the notifier.
I decided to use a launchd-agent for the cronjb, because this also runs if Mac is started later. Cron-jobs just run if your mac is already on at that time.
For a comparison of cronjob vs launchd, I recommend reading this.
Here's my configuration which runs every day at 10am and 3pm. The script, called by the agent, is located at /usr/local/bin/homebrew-update-notifier
.
<?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>EnableGlobbing</key>
<false/>
<key>Label</key>
<string>homebrew.simonsimcity.update-notifier</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/usr/local/bin/homebrew-update-notifier</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/homebrew.simonsimcity.update-notifier.err</string>
<key>StandardOutPath</key>
<string>/tmp/homebrew.simonsimcity.update-notifier.out</string>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>10</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Hour</key>
<integer>15</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</array>
</dict>
</plist>
You will now be notified if a new update is available. Call brew upgrade
if you feel outdated, or include it in the script.