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

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

linux脚本后台监控执行指定程序的状态(假设程序是死的重新启动程序)的更多相关文章

  1. linux脚本: 后台启动程序并重定向输出信息脚本

    后台启动程序并重定向输出信息脚本 新建文件mstart, 写入下面代码. #!/bin/bash $1 1>/etc/null 2>&1 & 说明 1>/etc/nu ...

  2. linux脚本后台运行

    一般情况下,linux运行脚本是随着终端的关闭而关闭的,那么怎么让脚本能够在后台运行并且不随终端关闭而关闭呢? 这时用到的是nohup命令 格式: nohup 脚本路径 & 例: nohup ...

  3. 几种linux脚本的简单执行方法

    1.hash脚本文件名:assign 内 容:#!/bin/sh cd $1ls 执行: [root@db2 ~]# sh helle2.sh /usr 或者[root@db2 ~]#./helle2 ...

  4. Shell脚本实现每个工作日定时执行指定程序

    我们可能会遇到这样的情景:必须在每个工作日定时执行Linux服务器上的某个程序.那么有没有办法实现这一功能呢?答案是肯定的.我们可以运用Shell脚本简单实现这一功能. 原理很简单,Shell脚本内部 ...

  5. centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课

    centos shell编程4[分发系统] 服务器标准化  mkpasswd 生成密码的工具  expect讲解   expect传递参数   expect自动同步文件  expect指定host和要 ...

  6. Runtime.getRuntime.exec()执行linux脚本导致程序卡死有关问题

    Runtime.getRuntime.exec()执行linux脚本导致程序卡死问题问题: 在Java程序中,通过Runtime.getRuntime().exec()执行一个Linux脚本导致程序被 ...

  7. Linux下如何让jar包程序在后台一直执行

    Linux下如何让Jar包程序在后台一直执行 shell命令 nohup java -jar xxx.jar & &:让程序后台执行. nohub:让程序控制台输出转移到nohub.o ...

  8. linux 命令后台执行

    我想把updatedb命令(用于重新建立整盘索引的命令)放在后台运行.因为我不想眼睁睁的看着机器建立索引,我还想编会儿程序呢: # updatedb & [1] 23336 注释:在所要执行的 ...

  9. Linux 服务器系统监控脚本 Shell【转】

    转自: Linux 服务器系统监控脚本 Shell - 今日头条(www.toutiao.com)http://www.toutiao.com/i6373134402163048961/ 本程序在Ce ...

随机推荐

  1. string的不可变性

    1.不可变性 代码如下: static void Main(string[] args){string str1 = "a";string str2 = str1;str2 = & ...

  2. shell程序设计(转)

    1.shell脚本的基本概念: (1)Shell执行的是称为shell程序,这些程序通常被称为脚本. (2)Shell是一个用户和系统间接口的程序,它允许用户向操作系统输入需要执行的命令. (3)sh ...

  3. java之redis篇(spring-data-redis整合) (转)

    redis的知识:官网 1,利用spring-data-redis整合 项目使用的pom.xml: <project xmlns="http://maven.apache.org/PO ...

  4. UVA 10201 Adventures in Moving - Part IV(dp)

    Problem A: Adventures in Moving - Part IV To help you move from Waterloo to the big city, you are co ...

  5. 【cocos2d-js公文】十七、事件分发机制

    简单介绍 游戏开发中一个非常重要的功能就是交互,假设没有与用户的交互.那么游戏将变成动画,而处理用户交互就须要使用事件监听器了. 总概: 事件监听器(cc.EventListener) 封装用户的事件 ...

  6. git使用说明

    1,git clone git://github.com/schacon/simplegit.git git工作目录,暂存目录,本地代码仓库都有代码了. 2,git pull git://github ...

  7. TPanel的默认颜色存储在dfm中,读取后在Paint函数中设置刷子的颜色,然后填充整个背景

    声明如下: TCustomPanel = class(TCustomControl) private FFullRepaint: Boolean; FParentBackgroundSet: Bool ...

  8. javascript addEventListener方法

    addEventListener是一个侦听事件并处理相应的函数. DOM方法 addEventListener() 和 removeEventListener()是用来分配和删除事件的函数. 这两个方 ...

  9. 用XCA(X Certificate and key management)可视化程序管理SSL 证书(3)--创建自己定义的凭证管理中心(Certificate Authority)

    在第"用XCA(X Certificate and key management)可视化程序管理SSL 证书(2)---创建证书请求"章节中,我们介绍了怎样用XCA创建SSL证书请 ...

  10. 关于Android配色 自适应颜色的实现

    在Android4.4系统中,更加详细地介绍了关于颜色的细节并提供了使用colour的新教程,以使我们的应用更加独一无二.也就是说,作为一个设计师或者开发者,为你的APP做完美的配色已经变成了你的职责 ...