我正在 Linux EC2 实例(标准 AMI)上运行 python 脚本,但在通过 Crontab 执行 python 脚本时遇到问题。我已经运行了另一个 cron 作业并遵循相同的格式。我认为我错过了一些简单的事情,但很难确定原因。这是我运行 crontab -e
*/5 * * * * ~/scripts/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron
*/1 * * * * ~/scripts/python cpu-util.py
我在日志中收到的错误是/bin/sh:/root/scripts/python: No such file or directory
我对这个错误消息有点困惑,因为我登录时的路径是 ~/scripts,其中有我的 Python 脚本。
我还尝试了 */1 * * * * ~/scripts python cpu-util.py
(我认为这更有意义),但是 rearranged my code based on this other post to no avail 。
此外,我从 root 用户还是 ec2 用户运行这些任务有什么关系吗?为了安全起见,我只是将相同的脚本放入两个问题中(抱歉,如果这是两个问题合二为一,但只是对此感到好奇......)
任何意见都会很棒。谢谢!
最佳答案
在您正在寻找的行中
the python application inside your scripts folder
我想这不是你想要的。试试这个:
*/1 * * * * /usr/bin/python ~/scripts/cpu-util.py
我认为这应该可行。
您也可以使用 ./直接调用它,只需将 python 脚本作为第一行即可。
#!/usr/bin/env python
然后你可以像这样运行
*/1 * * * * /usr/bin/sh ~/scripts/cpu-util.py
关于python - Crontab Python 脚本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47311758/