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




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

  • 相关阅读:
    IOS中UIImage用代码压缩
    自定义UILabel设置垂直方向的居上,居中,居下
    IOS开发之数据加密与解密:AES256+Base64转码
    IOS开发之网络数据Json处理
    Unity3d中CharacterController的移动和碰撞分析
    关于Unity3d中物体之间碰撞检测的方法
    WPF 调用Win32控件
    C# 扩展方法
    颜色空间转换 RGB到HSV
    加速计算技术-- Intel 的IPP库
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4652591.html
Copyright © 2011-2022 走看看