Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用cron的Github自动更新_Bash_Git_Github_Cron - Fatal编程技术网

Bash 使用cron的Github自动更新

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

我有一个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
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发送给您的邮件以确定问题所在

感谢您的回答,不幸的是,它不起作用。。。。