问题
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