0

I have a simple crontab to automatically keep my brew setup up to date, since if you update rarely the process can take ages

    ❯ crontab -l
    MAIL=my_mail@gmail.com
    @weekly bash /Users/directorytree/crontab/my_tab

The shell script I run here is very simple. I want to learn to use crontab, and these are tasks I really wish to automate:

    #!/usr/bin/env zsh
    
    brew update
    brew upgrade

The problem is it seems that I simply does not run. Since every time I run either brew update or brew upgrade manually, my Mac seems to go leaps in brew versions and update a lot of packages and casks.

What can I do to ensure and test that my crontabs do in fact run?

zeebrah
  • 116
  • 1
  • 10
  • Running `cron` jobs on MacOS is a bit of a moving target. https://medium.com/macoclock/automate-running-a-script-using-crontab-on-macos-88a378e0aeac looks like one reasonably recent treatise but it's on Medium so the quality might be what it often is. – tripleee Apr 05 '22 at 11:40
  • For general `cron` troubleshooting, [Cron job not running](https://stackoverflow.com/questions/22743548/cronjob-not-running) has a very comprehensive set of answers. – tripleee Apr 05 '22 at 11:41
  • Why are you running your `zsh` script with Bash? It doesn't appear to make a difference in this particular case, but you also seem to be confused. Perhaps start with [Difference between `sh` and `bash`](https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash) though it doesn't cover Zsh; there's probably a separate question about the differences between Zsh and `sh`, or even Zsh and Bash. – tripleee Apr 05 '22 at 11:42
  • Good point about different shells @tripleee. I mostly use `zsh` and understand the difference. The script itself and automation for it were written several weeks apart. Seems that I forgot what I wrote and so defaulted to `bash` for running basic commands. I will be sure to correct this. Thanks! – zeebrah Apr 05 '22 at 11:53
  • @zeebrah That's why you shouldn't run shell scripts with the `bash` command (or `zsh` or `sh` for that matter) -- make sure the script is executable, and run it just by giving its path and letting the shebang control what interpreter is used. That said, my guess about the actual problem would be that `brew` probably isn't in one of the directories in the (very minimal) `PATH` that cron uses by default. – Gordon Davisson Apr 05 '22 at 17:06

0 Answers0