我写的监控脚本

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
~                                                                 

你可能感兴趣的:(status,null,sleep,running,failure)