zoukankan      html  css  js  c++  java
  • 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


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




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

  • 相关阅读:
    Kubernetes 无法删除pod实例的排查过程
    kubeadm 生成的token过期后,集群增加节点
    linux 常规操作EOF写法梳理
    linux下EOF写法梳理
    容器云之弹性伸缩
    QEMU,KVM及QEMU-KVM介绍
    听听八年阿里架构师怎样讲述Dubbo和Spring Cloud微服务架构
    代码内存泄露检测(1) MLeaksFinder (Wechat开源) + FBRetainCycleDetector (FaceBook开源)
    Xcode 创建使用多个 target (1)
    iOS 多线程的简单理解(4) 线程锁的简单使用
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4652591.html
Copyright © 2011-2022 走看看