我想打一个sh脚本,将只在任何时候运行最多一次。说,如果我执行的是剧本,然后我再去执行的是剧本,我怎么让这个如果脚本的第一EXEC仍然是工作,第二个将因错误而失败。即我需要检查,如果脚本在那里做任何事情之前其他运行。我怎么会去这样做?
I want to make a sh script that will only run at most once at any point. Say if I exec the script then I go to exec the script again, how do I make it so that if the first exec of the script is still working the second one will fail with an error. I.e. I need to check if the script is running else where before doing anything. How would I go about doing this??
脚本我有一个运行长时间运行的过程中(即运行永远)我想使用类似cron来调用脚本的情况下,该进程失败,每15分钟左右,就会被下一个cron运行脚本重新启动..
The script I have runs a long running process (i.e. runs for ever) I wanted to use something like cron to call the script every 15mins so in case the process fails, it will be restarted by the next cron run script...
干杯。
推荐答案您需要一个PID文件,也许是这样的:
You want a pid file, maybe something like this:
pidfile=/path/to/pidfile if [ -f "$pidfile" ] && kill -0 `cat $pidfile` 2>/dev/null; then echo still running exit 1 fi echo $$ > $pidfile更多推荐
bash脚本只运行一次
发布评论