linux用于后台监控指定程序运行状况的脚本(如果程序死了则重启程序)
#!/bin/shwhile truedops | grep "my_app" | grep -v "grep" > /dev/null#第一二个命令输出my_app的运行情况,第二个命令去掉带有grep的条目,然后把结果重定向到null里面不要回显if [ "$?" -eq 1 ] # 1 : 表示有 ; 0 :表示没有then./my_app &
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
更多推荐
所有评论(0)