Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command to run script at intervals

I have this command that I run from a terminal in ubuntu

python2.5 /home/me/web/gae/google_appengine/dev_appserver.py /home/me/web/gae/APPLICATION/trunk

I need to stop this running and then restart it every 10 seconds - I can run this from a .sh file if necessary.

What would be the best way to do this? I'd like it to all be in one script if possible so not that keen on using cron jobs to run it - surely there is some way of doing a loop with a delay in purely in a shell script?

The closest equivalent I can think of is JavaScript's setInterval(function(),10000);

like image 441
kieran Avatar asked Jul 05 '11 13:07

kieran


Video Answer


2 Answers

You could try something like this:

while true; do
  python2.5 /home/me/web/gae/google_appengine/dev_appserver.py /home/me/web/gae/APPLICATION/trunk &
  sleep 10
  kill $!
done

I.e.: Loop forever (while true), start the python script in background, wait for 10 seconds (sleep 10) and kill the background process (kill $!).

like image 197
bmk Avatar answered Oct 16 '22 02:10

bmk


I like ~$ watch -n sec command

i.E.

watch -n 10 ls /home/user/specialdata

watch -n 30 csync /dir/A /remote/dir/B
like image 39
PlagTag Avatar answered Oct 16 '22 02:10

PlagTag