简体   繁体   English

树莓派上的 Crontab 没有运行

[英]Crontab on raspberry pi not running

I have a python file on my Raspberry pi and I'm trying to have it run daily.我的 Raspberry pi 上有一个 python 文件,我试图让它每天运行。 I've checked the script by runing it directly, which works perfectly.我已经通过直接运行它来检查脚本,它完美地工作。 But when I set it up in crontab, it's not running on scheduled time.但是当我在 crontab 中设置它时,它没有按预定时间运行。 Can someone help me understand what's going wrong?有人可以帮助我了解出了什么问题吗?

Here's what I put in crontab这是我放在 crontab 中的内容

27 09 * * * /usr/bin/python3 /home/pi/myfile.py

I feel it might be related the python version?我觉得这可能与python版本有关? At the beginning of my python script I have this line #!/usr/bin/env python在我的 python 脚本的开头,我有这一行#!/usr/bin/env python

The shebang-Line ( #!/usr/bin/env python ) is only used when called by a shell to determine the interpreter to use. shebang-Line ( #!/usr/bin/env python ) 仅在被 shell 调用以确定要使用的解释器时使用。

If your script works with如果您的脚本与

/usr/bin/python3 /home/pi/myfile.py

in your shell, it should work in the Crontab File.在你的 shell 中,它应该在 Crontab 文件中工作。

If it does not it is a possibility that the python script is not compatible with Python3 and you need to use Python 2. You may test your script with either如果不是,则可能是 Python 脚本与 Python3 不兼容,您需要使用 Python 2。您可以使用以下任一方式测试您的脚本

/usr/bin/python /home/pi/myfile.py

or simply或者干脆

/home/pi/myfile.py

If either of these commands will run the script without problem use this command in your contab.如果这些命令中的任何一个都可以毫无问题地运行脚本,请在您的 contab 中使用此命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM