首页 > 其他 > 详细

我写的监控脚本

时间:2014-09-03 11:26:37      阅读:279      评论:0      收藏:0      [点我收藏+]

1

#!/bin/bash
pid=`ps -ef  | grep tomcat8082 | grep -v grep | wc -l`
port=`netstat -anplt | grep 8082 | wc -l `
path=/usr/tomcat/tomcat8082/bin/startup.sh
if [ $pid = 1 -a $port -eq 1 ];then
   echo "tomcat is running"
else
   echo "tomcat8082 is stoped and now let‘s run it"
   sleep 3
   echo "now restart tomcat8082"
    [ -x $path ] && sh $path > /dev/null 2>&1 && status="sucess" || status="failure"
   sleep 5
   pid=`ps -ef  | grep tomcat8082 | grep -v grep | wc -l`
   port=`netstat -anplt | grep 8082 | wc -l `
   pid8082=`ps -ef |grep tomcat8082|grep -v grep |awk ‘{print $2}‘`
   if [ $pid -ne 1 -a $port -ne 1 ];then
    while true
   do
    kill -9 $pid8082
    [ $? -eq 0 ]  && break
   sleep 1
   done
       [ -x $path ] sh $path && status="success" || status="failure"
   fi
fi
~

2                                                                                                                                           #!/bin/bash
port=`netstat -anplt |grep httpd | wc -l `
process=`ps -ef |grep httpd | wc -l `
path=/etc/init.d/httpd
if [ $port -eq 1 -a $process -gt 1 ];then
        echo "http is running"
     else
        echo "http is stopping,do you want to start httpd?"
        read -p "start [1] \t not start [2] :" a
        [ $a -eq 1 ] && [ -x $path ] && $path start
        if [ $port -ne 1 -o $process -le 1 ];then
           while true
           do
           pkill httpd
           [ $? -eq 0 ]  && break
           done
          [ -x $path ] && $path start
        fi
        [ $a -eq 2 ] && exit
fi~                          

3

   #!/bin/bash
#stat=`nmap 192.168.0.200 -p 80 | grep open |wc -l`
ip=192.168.0.200
wget -T 10 -q  192.168.0.200
if [ $? -eq 0 ];then
       echo "the httpd service of $ip is running"
     else
        /etc/init.d/httpd start
fi
~               

4

#!/bin/bash
#stat=`nmap 192.168.0.200 -p 80 | grep open |wc -l`
[ -f /etc/init.d/functions ] && . /etc/init.d/functions ||exit 1
httpcode=`curl -I -s 192.168.0.200 | head -1 | awk ‘{print $2}‘`
if [ "$httpcode" == "200" ];then
       action "http is running." /bin/true
     else
       action "http is not running." /bin/false
      sleep 1
       /etc/init.d/httpd start >/dev/null  && \
      action "nginx is started." /bin/true
fi
~                                                                 

我写的监控脚本

原文:http://wangxm.blog.51cto.com/5688274/1548153

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!