zoukankan      html  css  js  c++  java
  • 用shell脚本监控进程是否存在 不存在则启动的实例

    最近发现测试环境里的virgo-tomcat会莫名的自己挂掉,通过ps -ef | grep virgo-tomcat 也查不到进程ID,也看不到错误日志信息。于是想到一个不得已的办法,

    写一个脚本来监测virgo-tomcat进程是否存在,如果不存在就启动它。以下是脚本的具体内容:

     1 #!/bin/sh
     2 
     3 while true;do
     4 count=`ps -ef|grep virgo-tomcat|grep -v grep`
     5 if [ "$?" != "0" ];then
     6 echo ">>>>no platform,run it"
     7 ./bin/startup.sh
     8 else
     9 echo ">>>>platform is runing..."
    10 fi
    11 sleep 10
    12 done

    然后执行nohup sh ./monitorprocess.sh > monitorprocessout.file 2>&1,该命令的作用是让你退出账户之后该进程可以继续运行,并且可以让脚本里echo展示的内容重定向到monitorprocessout.file中,然后用tail -f monitorprocessout.file来实时的看到echo展示的内容,来判断该shell脚本是否已经在后台运行良好

  • 相关阅读:
    gems gems gems
    poj 6206 Apple
    lightoj1341唯一分解定理
    lightoj1370欧拉函数
    约瑟夫环lightoj1179
    拓展欧几里得算法
    RMQ算法
    poj1502MPI Maelstrom
    poj1860Currency Exchange
    生成全排列
  • 原文地址:https://www.cnblogs.com/testermark/p/4293133.html
Copyright © 2011-2022 走看看