为什么我的cron作业没有正确调用.sh脚本中的命令?

huangapple go评论79阅读模式
英文:

Why is my cronjob not properly calling commands within .sh scripts?

问题

我在Ubuntu中遇到了关于cronjobs的问题,它正在调用某些命令但不调用其他命令。

cronjob

30 * * * * /bin/bash /home/path/script/start.sh &>> /tmp/test.txt

start.sh

#!/bin/bash

cd /home/path/script

echo "Its working"

/usr/bin/git fetch
/usr/bin/git pull origin

echo "git"

/usr/bin/python3 /home/path/script/main.py &

echo "end"

/var/log/syslog

CRON[362212]: (ubuntu) CMD (/bin/bash /home/path/script/start.sh &>> /tmp/test.txt)

test.txt

Its working
Updating n83aw46..215iebd
git
end

当我运行 git log 时,它仍然显示以前的git提交,当我运行 ps -ef | grep .py 时没有显示任何内容。

我已确认cron守护程序正在运行。ps -ef 命令也与我的测试Python脚本一起工作。我还验证了 main.pystart.sh 文件都已经执行了 chmod +x

英文:

I'm having an issue with cronjobs in Ubuntu where its calling some commands and not others

cronjob

30 * * * * /bin/bash /home/path/script/start.sh >> /tmp/test.txt

start.sh

#!/bin/bash

cd /home/path/script

echo "Its working"

/usr/bin/git fetch
/usr/bin/git pull origin

echo "git"

/usr/bin/python3 /home/path/script/main.py &

echo "end"

/var/log/syslog

CRON[362212]: (ubuntu) CMD (/bin/bash /home/path/script/start.sh >> /tmp/test.txt)

test.txt

Its working
Updating n83aw46..215iebd
git
end

When I git log it still shows the previous git commit and when I run ps -ef | grep .py nothing shows up.

I have confirmed cron daemon is running. ps -ef command also works with my test python script. I've also verified that both the main.py and start.sh files has chmod +x

答案1

得分: 0

@Philippe,你建议添加另一个错误日志 ... >> /tmp/test.txt 2> /tmp/test.err 帮助我解决了这个问题。

本地更改与 git pull 冲突,因此我不得不储藏(stash),然后拉取(pull),然后重新应用储藏。

英文:

@Philippe Your suggestion of adding another err log ... >> /tmp/test.txt 2> /tmp/test.err helped me resolve the issue.

There was a conflict with local changes and git pull. So I had to stash, pull then re-apply the stash.

huangapple
  • 本文由 发表于 2023年7月3日 15:34:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602700.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定