我已经设置了一个 cronjob,如下所示,当我从 shell 运行脚本时,脚本运行得很好,但是当通过 cronjob 运行时,我遇到了以下错误。
知道 cronjob 是做什么的吗?这里有环境问题吗?有调试的指针吗?
28 21,0 * * * /usr/bin/python /local/mnt/workspace/user/Automation/script.py project branch
错误
Traceback (most recent call last):
File "/local/mnt/workspace/user/Automation/script.py", line 74, in <module>
output = phCmdoutput(phCmd)
File "/local/mnt/workspace/user/Automation/script.py", line 28, in phCmdoutput
phPipe = Popen(phCmd, stdout=PIPE, stderr=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
最佳答案
看起来 phPipe = Popen(phCmd, stdout=PIPE, stderr=PIPE)
句子中的 phCmd
正在使用某些文件或程序本身的相对路径名。你可以检查一下,然后将它们更改为绝对路径。
关于python - 作为 cronjob 运行时脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18248197/