站长资讯网
最全最丰富的资讯网站

Linux简单监控服务脚本解析

  [root@hechaojie monitor]# cat process.sh   #!/bin/sh    ctime=`date +%Y-%m-%d %H:%S:%S`  server_name=hechaojie  server_dir=/data/$server_name/tomcat    echo $ctime' 监听服务运行状态,'$server_name    function checkserver(){      count=`ps -ef |grep $2 |grep -v "grep" |wc -l`      echo '服务数:'$count      if [ 0 == $count ];then          echo $1'已停止,正在启动...'      #source /data/shell/killprocess.sh $1          echo '启动完毕,3s启动server'          sleep 3          source /data/$1/deploy/start.sh          count=`ps -ef |grep $2 |grep -v "grep" |wc -l`      echo '启动完成,服务数:'$count      fi      return $count  }    checkserver $server_name $server_dir  

2.crontab定时任务扫描

  */2 * * * * source /etc/profile && sh /data/shell/monitor/process.sh >> /var/log/process.log  

赞(0)
分享到: 更多 (0)
网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号