简体   繁体   中英

how to automate running a python script

How can I automate running of 3 python scripts. Suppose, I have 3 scripts say a.py,b.py and c.py.

Here a.py runs a web crawler and saves it as a xml file. Now b.py parses the xml file generated and saves as a pickle file. Now c.py inserts the list from pickle file to database.

Is there a way to automate this?

Just make a shell script which does

python a.py && python b.py && python c.py

The && in bash is for chaining commands consecutively, eg here b.py would only execute if a.py completed successfully (ie returned 0).

Save it in a file with no extension (some version of cron won't use .sh files, I found this out the long and frustrating way), then put the location of that shell script in your cron table using crontab -e . There is plenty of information on superuser about how to schedule cron jobs, so I recommend to search there for this information rather than here on SO (which is more about programming).

Write a wrapper python script that imports a, b and c and runs then in sequence (with error checking, notification and accounting). Then schedule this wrapper using the system cron daemon (if on UNIX).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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