使用 cron 运行 python 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4460262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
running a python script with cron
提问by Antonis
It might be very simple question, but how could I run a python script on my fedora dist every 2 days?
这可能是一个非常简单的问题,但是我怎么能每 2 天在我的 Fedora dist 上运行一个 python 脚本呢?
Thanks
谢谢
Antonis
安东尼斯
采纳答案by Senthil Kumaran
It is a question on cron. First is add a SHEBANG line on top of your python script.
这是一个关于cron的问题。首先是在你的 python 脚本之上添加一个 SHEBANG 行。
#!/usr/bin/env python
Make your script executable with chmod +x
使您的脚本可执行 chmod +x
And do a crontab -e and add 0 0 */2 * * /path/to/your/pythonscript.py
并执行 crontab -e 并添加 0 0 */2 * * /path/to/your/pythonscript.py

