开发者

Linux command to run script at intervals

开发者 https://www.devze.com 2023-03-17 04:44 出处:网络
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 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);


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


I like ~$ watch -n sec command

i.E.

watch -n 10 ls /home/user/specialdata

watch -n 30 csync /dir/A /remote/dir/B


there is sleep and at if you don't like cron

echo "print after 3min again"
sleep 180  # or sleep +3m
echo "hello again, 3min passed"

Read the man pages, play with those a bit, and I think it'd be easy to build what you want, around those.

0

精彩评论

暂无评论...
验证码 换一张
取 消