英文:
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.py
和 start.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论