how to update homebrew with Cron on Mac os

Viewed 7311

I've been discvering some long lasting linux techs to help automate my daily work. I found cron to be very powerful if I can use it to check the updates of some packages I have on my system.

For example, I want to update my Homebrew everyday at 11pm. What I did is, with sudo crontab -u user -e, I opened up crontab in Vim. And I put following commands into it, to make updates for homebrew and send me an email.

Here's the code:

MAILTO=myemail@foo.com
* 23 * * * brew update

and I save it to wait for magic happens. Instead of excuting this command, in the email I recieved, it says /bin/sh: brew : command not found

But when I type /bin/sh in terminal to open sh and type in brew update it will update the Homebrew怂

What did I do wrong with my crontab configuration?

Any help will be appreciated!

4 Answers

Personally the way I handle this is:

  • Download CronniX (it's discontinued but still works, e.g. brew cask install cronnix)

  • Setup the job within the UI via /usr/local/bin/brew update to run every hour.

Let it tick over in the background!

enter image description here

Related