Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constantly running a script on my server

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

like image 547
Andrew Avatar asked Jan 31 '26 22:01

Andrew


2 Answers

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.

like image 148
wim Avatar answered Feb 02 '26 12:02

wim


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.

like image 32
Wesley Avatar answered Feb 02 '26 10:02

Wesley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!