简体   繁体   English

运行Python脚本-Cron

[英]Run Python Script - Cron

How can I run a python script once at exactly 12:00PM on Wednesday (Jan 21)? 如何在周三(1月21日)正好12:00 PM运行一次python脚本?

I've added #!/usr/bin/env python to the top of my script and made the script executable with chmod +x 我在脚本顶部添加了#!/usr/bin/env python ,并使用chmod +x使脚本可执行

I know I want to do something like crontab -e 0 0 * * * /path/to/my/pythonscript.py but I'm not exactly sure how to get it to be a specific time... 我知道我想做类似crontab -e 0 0 * * * /path/to/my/pythonscript.py但是我不确定如何将其设置为特定时间。

To run on 21 Jan at 12pm you will need the following line in your crontab file: 0 12 21 1 * /path/to/my/pythonscript 要在1月21日下午12点运行,您的crontab文件中需要以下行: 0 12 21 1 * /path/to/my/pythonscript

Edit the crontab file with crontab -e 使用crontab -e编辑crontab文件

The first number is minute , the second number is hour , the third one day of month , the fourth month , the fifth is day of week (in this case a * for any day of week), then the path. 第一个数字是分钟 ,第二个数字是小时一个月的第三个 ,第四个月 ,第五个是星期几 (在这种情况下,星期几是*),然后是路径。

The wikipedia entry on Cron is really helpful if you want to change the times. 如果您想更改时间,Cron上的Wikipedia条目确实很有帮助。

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

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