Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update homebrew with Cron on Mac os

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:

[email protected]
* 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!

like image 943
Ian Zhao Avatar asked Dec 11 '13 19:12

Ian Zhao


1 Answers

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.

like image 114
Donovan Avatar answered Sep 21 '22 05:09

Donovan