4

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?

2
  • 1
    What operating system are you on? Also, what do you mean by automate? Do you want them to run on a fixed schedule or in response to certain events? Commented Feb 1, 2012 at 5:44
  • I'm using ubuntu 11.10, by automate i mean to say that I want these 3 scripts to run every 2-3 hours. Commented Feb 1, 2012 at 5:46

2 Answers 2

7

Just make a shell script which does

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

The && in bash is for chaining commands consecutively, e.g. here b.py would only execute if a.py completed successfully (i.e. 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).

Sign up to request clarification or add additional context in comments.

2 Comments

*/2 * * * * /home/ching/Desktop/scrapper/scrap im using this to run my scripts in crontab every 2 minutes. But i dont see any xml file generated. Is something wrong in this?
have you chmod +x on the script? you can use run-parts --test to check what cron will run
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.