博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux脚本后台监控执行指定程序的状态(假设程序是死的重新启动程序)
阅读量:4352 次
发布时间:2019-06-07

本文共 800 字,大约阅读时间需要 2 分钟。

#!/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

把上面的脚步执行命令加入到/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

版权声明:本文博客原创文章。博客,未经同意,不得转载。

转载于:https://www.cnblogs.com/hrhguanli/p/4652591.html

你可能感兴趣的文章
利用套接字实现进程通信一例
查看>>
linux中shell变量$#,$@,$0,$1,$2的含义解释
查看>>
常用的shell命令整理
查看>>
A Brief Introduction to the Design of UBIFS
查看>>
了解你的Linux系统:必须掌握的20个命令
查看>>
js setInterval 启用&停止
查看>>
knockoutJS学习笔记04:监控属性
查看>>
18.10.6 考试总结
查看>>
iptables防火墙网路安全实践配置
查看>>
ASP.net Web窗体添加多条数据到数据库
查看>>
PHP面向对象(三)
查看>>
mysql与实际时间有8小时差怎么办
查看>>
docker 常用命令
查看>>
微信小程序 - 参数传递
查看>>
在Centos7上安装Oracle
查看>>
Linux下启动/关闭Oracle
查看>>
session和cookie的区别
查看>>
oracle 数据库、实例、服务名、SID
查看>>
web.xml文件的作用
查看>>
linux下oracle调试小知识
查看>>