linux shell脚本不重复在后台运行,急急急

LionSoul 2010-07-20 02:43:11
linux下使用shell写了一个监控脚本,需要使用&在后台运行,可以在后台运行很多个,但是客户要求只能运行一个,请问各位大侠怎么写才能让脚本不重复执行,使用ps我试了不行,急急急!!!!!!!!!!!!
...全文
85 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
LionSoul 2010-07-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 playmud 的回复:]
如果自己写shell


Python code

#!/bin/sh
pidfile=/tmp/.pid.$0

kill -0 `cat $pidfile`
if [ $? == 0 ]
then
echo "the shell:"$0"is running"
exit 1
fi

echo $$>$pidfile


# ……
[/Quote]

虽然没有达到我的目的,但是你后面的“如果想放入系统启动里面,搜索一下
/etc/inittab respawn
系统自动帮你监控shell,如果shell断了会帮你起来。 ”对我有用,给分吧,谢谢
LionSoul 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 steptodream 的回复:]
看来你一着急发了2个!
[/Quote]

对,等着上线要呢,不过已经弄好了,谢谢
playmud 2010-07-20
  • 打赏
  • 举报
回复
如果自己写shell


#!/bin/sh
pidfile=/tmp/.pid.$0

kill -0 `cat $pidfile`
if [ $? == 0 ]
then
echo "the shell:"$0"is running"
exit 1
fi

echo $$>$pidfile


# your scrip

如果想放入系统启动里面,搜索一下
/etc/inittab respawn
系统自动帮你监控shell,如果shell断了会帮你起来。
steptodream 2010-07-20
  • 打赏
  • 举报
回复
看来你一着急发了2个!

2,161

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 UNIX文化
社区管理员
  • UNIX文化社区
  • 文天大人
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧