Linux命令每隔一段时间运行脚本

kie*_*ran 9 linux bash shell command

我有这个命令,我从ubuntu的终端运行

python2.5 /home/me/web/gae/google_appengine/dev_appserver.py /home/me/web/gae/APPLICATION/trunk
Run Code Online (Sandbox Code Playgroud)

我需要停止此运行,然后每10秒重新启动一次 - 如果需要,我可以从.sh文件运行它.

最好的方法是什么?如果可能的话,我希望所有人都在一个脚本中,所以不要热衷于使用cron作业来运行它 - 当然有一些方法可以在shell脚本中做一个延迟的循环吗?

我能想到的最接近的等价物是JavaScript setInterval(function(),10000);

bmk*_*bmk 16

你可以尝试这样的事情:

while true; do
  python2.5 /home/me/web/gae/google_appengine/dev_appserver.py /home/me/web/gae/APPLICATION/trunk &
  sleep 10
  kill $!
done
Run Code Online (Sandbox Code Playgroud)

即:循环永远(while true),在后台启动python脚本,等待10秒(sleep 10)并终止后台进程(kill $!).


Pla*_*Tag 5

我喜欢 ~$ watch -n sec 命令

IE

watch -n 10 ls /home/user/specialdata

watch -n 30 csync /dir/A /remote/dir/B
Run Code Online (Sandbox Code Playgroud)