How to automate / run ‘brew cask upgrade’ as a cron job

command linecronhomebrewterminal

I wish to run brew cask upgrade in a cronjob, but it prompts for a password.

When I run the job as root all permissions are screwed up.

Howto run that command in a cronjob env? I use zsh.

~ brew cask upgrade
==> Casks with `auto_updates` or `version :latest` will not be upgraded
==> Upgrading 2 outdated packages:
java 13.0.1,9:cec27d702aa74d5a8630c65ae61e4305 -> 13.0.2,8:d4173c853231432d94f001e99d882ca7, keepassxc 2.5.2 -> 2.5.3
==> Upgrading java
==> Downloading https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_osx-x64_bin.tar.gz
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'java'.
==> Backing Generic Artifact 'openjdk-13.0.1.jdk' up to '/usr/local/Caskroom/java/13.0.1,9:cec27d702aa74d5a8630c65ae61e4305/jdk-13.0.1.jdk'.
Password:

Best Answer

I have tried using cron as well but it just won't go as well. Instead I wrote a script called macupdate that held the instructions for homebrew to upgrade all installed apps as well as for the mac to look for and download any MacOS updates, made it executable and selected it as a startup application.

brew update && brew upgrade && brew cask upgrade --greedy; mas upgrade;
sudo softwareupdate -i -a --restart