3

I need to write a python script that constantly checks a remote web service for updates. The faster it loops the better.

How do I get a script to run on my server over and over again without me having to manually start it each time? And if the server crashes or something, how does this script automatically start up again?

thanks

Andrew
  • 2,898
  • 4
  • 25
  • 23

3 Answers3

5

Rather than making your script loop many times, just write it to perform this task a single time. Then run the script multiple times, as often as you wish, as a cronjob. Edit your cron table to specify timings using the command crontab -e. You needn't worry about server restarts because cron will be started as a service automatically.

wim
  • 338,267
  • 99
  • 616
  • 750
2

If you really want to run it as fast as possible, there is an alternative to using cron which is write the python program as an endless loop and then start it as a background process using nohup python script.py &. The output of the python process will then be written in nohup.out.

Wesley
  • 2,204
  • 15
  • 14
0

It depends on how often you need to poll - AFAIK, you can only schedule cron to run once per minute (at the most frequent interval). But if that's OK, just use cron.

Otherwise, write an init script.

Community
  • 1
  • 1
pojo
  • 5,892
  • 9
  • 35
  • 47