Bash 使用cron的Github自动更新
我有一个cron任务,每5分钟执行一次。它启动一个bash脚本,查找是否在github上进行了更改,如果进行了更改,则更新代码。但是,如果有更新,则找不到更新,如果手动运行脚本,则会正常工作。有人帮我吗?提前谢谢,超值 Cron任务:Bash 使用cron的Github自动更新,bash,git,github,cron,Bash,Git,Github,Cron,我有一个cron任务,每5分钟执行一次。它启动一个bash脚本,查找是否在github上进行了更改,如果进行了更改,则更新代码。但是,如果有更新,则找不到更新,如果手动运行脚本,则会正常工作。有人帮我吗?提前谢谢,超值 Cron任务: */5 * * * * bash /home/pi/Documents/palamazon-bot/git-update.sh > /home/pi/Documents/bot-updates/latest.txt Bash脚本: #!/bin/bash
*/5 * * * * bash /home/pi/Documents/palamazon-bot/git-update.sh > /home/pi/Documents/bot-updates/latest.txt
Bash脚本:
#!/bin/bash
cd /home/pi/Documents/palamazon-bot
if [ $(git rev-parse HEAD) = $(git ls-remote $(git rev-parse --abbrev-ref @{u} | sed 's/\// /g') | cut -f1) ]; then
echo "No update"
else
echo "New update"
git pull > /dev/null 2>&1
npm i > /dev/null 2>&1
pm2 restart ./main.js > /dev/null 2>&1
echo "Code updated."
fi
谢谢你的帮助!超支。建议:
- 如果[“$(git…”=“…”],则引用比较的字符串
- 在脚本中设置
,然后在PATH
env-i./yourscript下运行测试
- 不要丢弃stdout和stderr,将它们保存在一个文件中
- 阅读cron发送给您的邮件以确定问题所在