下载terminal-notifier
brew install terminal-notifier
随便找个位置,放个脚本,命名autoUpdate.sh
#!/bin/zsh
tn=/usr/local/bin/terminal-notifier
b=/usr/local/bin/brew
# 配置代理服务器,有就配置,没有就换源
export http_proxy=
export https_proxy=
startTime=$(date "+%Y-%m-%d %H:%M:%S")
startTime_s=$(date "+%s")
# 注意这个地方要修改成你的用户名,查看日志也在这个地方查看
logFile=/Users/youusername/logs/homebrew/stdout.log
updateMsg=$($b update &)
wait
upgradeMsg=$($b upgrade &)
wait
logMsg="${updateMsg}${upgradeMsg}"
notifyMsg="${updateMsg}${upgradeMsg}"
endTime_s=$(date "+%s")
sumTime=$(($endTime_s - $startTime_s))
echo $notifyMsg | $tn -title 'brew auto update' -sound default -execute "open $logFile"
echo "================START AT [${startTime}]================\
\n\n ${logMsg}\n\n total: ${sumTime}s\n======================\
========================================\n\n" >>$logFile
配置crontab
我自己使用zsh,如果使用默认的bash就把zsh改一下,别忘记自己刚才放脚本的位置,也自己配一下,另外自动执行时间按照强迫症程度自行配置
0 */3 * * * zsh /Users/yourusername/shell/autoUpdate.sh>/dev/null 2>&1
大功告成,直接点击更新提示就可以打开日志了