您的位置:首页 > 运维架构 > Shell

自动监控进程并启动的shell脚本

2015-01-13 20:04 405 查看
实现过程:每个一秒ps一次进程是否存在,不存在则nohup启动之。

用法:autostart "test 1"

autostart()
{
if [ $# -eq 0 ]
then
echo "usage: autostart \"test 1\""
echo
return
fi
while [ 1 ]
do
ps -ef |grep -w "$1" |grep -w `whoami`|grep -vw grep|grep -vw tail
if [ $? -ne 0 ]
then echo "start process....."
nohup $1 >/dev/null &
else
echo "runing....."
fi
sleep 1
done
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: