Running python scripts consecutively in Crontab

安稳与你 提交于 2019-12-10 11:30:07

问题


I am attempting to run my compilation of scripts one after another every minute. Example: Assuming each script takes 2 seconds to finish:

start script 1 at 1:00, script 2 at 1:02, script 3 at 1:04, etc...

I assume it should look something like this

*/1 * * * * python script1.py && python script2.py && python script3.py

回答1:


* * * * * python /path/to/script1.py ; python /path/to/script2.py ; python /path/to/script3.py

Use && if you want to run the second script only if the first script is successful (exit code is 0)

Use ; if you want to always run the second script irrespective of first script's exit code

Always provide full path to your script in crontab




回答2:


Your cron entry is fine.

You may want to create a wrapper script that calls all your scripts in sequence.




回答3:


Your cron entry should work. However, you may notice that it may fail because you didn't specify the absolute paths for the scripts.



来源:https://stackoverflow.com/questions/41412029/running-python-scripts-consecutively-in-crontab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!