I wanted Homebrew maintenance to stop interrupting whatever I had opened the terminal to do. I used a cron job.

1. Create a script with the update commands.#

Homebrew’s update refreshes package definitions. upgrade installs newer versions of installed packages. Those are different operations; refreshing the definitions does not upgrade every package.

Find your executable with command -v brew, then put that absolute path in a script. Cron does not inherit the setup in your .zshrc.

#!/bin/bash
set -eu

# Replace this with the output of: command -v brew
HOMEBREW_BIN=/absolute/path/to/brew

"$HOMEBREW_BIN" update
"$HOMEBREW_BIN" outdated

This checks what needs attention. Run brew upgrade yourself when you can deal with a changed dependency. My original script also updated gcloud; that is a separate maintenance decision, so it is outside this example.

2. Add a new crontab entry to execute said script.#

Save the script as /absolute/path/to/check-homebrew.sh. Test it manually with /bin/bash /absolute/path/to/check-homebrew.sh before scheduling it.

Back up the existing crontab before editing it. crontab -e opens the current user’s schedule. An example that checks once a week, at 10:00 on Monday, is:

0 10 * * 1 /bin/bash /absolute/path/to/check-homebrew.sh

There is no trailing &: cron already starts the job independently of your terminal. The computer must be awake for this schedule to run; this example does not arrange catch-up after sleep. For macOS-specific scheduling, Apple’s launchd documentation is another place to start.

3. Monitor executions#

Cron can mail command output if local mail delivery is configured. That is not a guarantee that a message will reach an inbox you actually read. Check your system’s cron configuration, or redirect output to a log you maintain:

0 10 * * 1 /bin/bash /absolute/path/to/check-homebrew.sh >> /absolute/path/to/homebrew-check.log 2>&1

Use one of these entries, not both. The log’s parent directory must exist. Appending output grows the file as jobs produce output; it does not inherently grow exponentially. Rotate or trim the file if you keep this running.

What this little script taught me#

For the distinction between updating definitions and upgrading packages, see the Homebrew manual.