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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With