【发布时间】:2019-10-17 17:52:13
【问题描述】:
我使用 RaspberryPi 3 和 UbuntuMate 16.04。在它上面,我想每天午夜启动一个小 Python (3.5) 程序。为此我调用了一个小 shell 脚本,这样我就可以轻松地切换到想要的目录。
crontab:
5 0 * * * /path/to/script/start.sh
start.sh(是的,它是可执行的):
#!/bin/bash
cd /path/to/wanted/workingDir/
python3.5 ControllerQueue.py
#also tried: python3.5 ControllerQueue.py &
现在,如果我从终端执行程序或脚本,一切正常。但是,如果我使用 crontab,它会启动脚本并在之后立即停止。我也尝试直接运行程序但得到相同的结果。路径是正确的,因为我从 crontab 文件中复制了 workingDir 路径并通过终端启动它。
有什么我忽略的吗?
【问题讨论】:
-
我已经在我的 python 脚本中添加了它,但感谢您的参考:)
-
检查从
cron运行的环境PATH,将此行添加到您的start.sh:set|grep PATH >> /tmp/start.sh.log。验证python3.5是否在您的PATH中。 -
你是对的,python 不在我的 cronjobs 使用的 PATH 中。我添加了它,但我仍然有同样的问题。 python 脚本启动一秒钟后又消失了。
-
将
>> /tmp/start.sh.log添加到start.sh的两行并检查输出。要捕获错误输出,请执行以下操作:how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash
标签: python python-3.x shell cron cron-task