首页 > 代码库 > linux用于后台监控指定程序运行状况的脚本(如果程序死了则重启程序)
linux用于后台监控指定程序运行状况的脚本(如果程序死了则重启程序)
#!/bin/sh
while true
do
ps | grep "main_3g" | grep -v "grep" > /dev/null
if [ "$?" -ne 0 ]
then
ls /root/main_3g > /dev/null
if [ "$?" -eq 0 ]
then
chmod 777 /root/main_3g
/root/main_3g &
echo "main_3g restart"
else
echo "main_3g is not exist."
fi
fi
ps | grep "main_4g" | grep -v "grep" > /dev/null
if [ "$?" -ne 0 ]
then
ls /root/main_4g > /dev/null
if [ "$?" -eq 0 ]
then
chmod 777 /root/main_4g
/root/main_4g &
echo "main_4g restart"
else
echo "main_4g is not exist."
fi
fi
sleep 5
done
while true
do
ps | grep "main_3g" | grep -v "grep" > /dev/null
if [ "$?" -ne 0 ]
then
ls /root/main_3g > /dev/null
if [ "$?" -eq 0 ]
then
chmod 777 /root/main_3g
/root/main_3g &
echo "main_3g restart"
else
echo "main_3g is not exist."
fi
fi
ps | grep "main_4g" | grep -v "grep" > /dev/null
if [ "$?" -ne 0 ]
then
ls /root/main_4g > /dev/null
if [ "$?" -eq 0 ]
then
chmod 777 /root/main_4g
/root/main_4g &
echo "main_4g restart"
else
echo "main_4g is not exist."
fi
fi
sleep 5
done
把上面的脚步运行命令加入到/etc/rc.d/rc.local里就行了,在后面添加
ls /root/mymonitor.sh > /dev/null
if [ "$?" -eq 0 ]
then
chmod 777 /root/mymonitor.sh
/root/mymonitor.sh &
echo "run /root/mymonitor.sh"
else
echo "/root/mymonitor.sh is not exist."
fi
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。