工作中用于服务重启后快速检查网站是否连通 (有bug,待修改)

#!/bin/bash
RETVAL=0
FAILCOUNT=0
LOG_FILE="/tmp/web_check.log"
SCRIPTS_PATH="/service/scripts"
MAIL_GROUP="763513751@qq.com"
function GETURLSTATUS(){
     for ((i=1;i<=3;i++))
     do
          wget -T 10 --tries=1 --spider http://$1 >/dev/null 2>&1
          [ $? -ne 0 ]&& let FAILCOUNT+=1;
     done
          if [ $FAILCOUNT -gt 1 ];then
               RETVAL=1
               NOWTIME=`date +"%m-%d %H:%M:%S"`
               SUBCONTENT="http://${HOST_NAME} service is erro,${NOWTIME}."
               echo "send to :$MAIL_USER ,TITLE:$SUCONTENT" > $LOG_FILE
                 for MAIL_USER in $MAIL_GROUP
                   do
                         mail -s "$SUBCONTENT" $MAIL_USER < $LOG_FILE
                   done
           else
               RETAVL=0
           fi
           return $RETVAL
}
#function end
[ ! -d "$SCRIPTS_PATH" ] && mkdir -p $SCRIPTS_PATH
[ ! -f "$SCTIPTS_PATH/domain.list" ] && {
   cat >$SCTIPTS_PATH/domain.list<<EOF
       www.baidu.com
       www.sina.com
EOF
}

#service check
for URL in `cat $SCRIPTS_PATH/domain.list`
     do
        echo -n "checking $URL: "
        GETURLSTATUS $URL && echo ok || echo no
     done
~                              

2 apache启动脚本

#!/bin/bash
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
case "$1" in
start)
      action "apache start." /bin/true
      sleep 1
      touch /service/scripts/a
;;
stop)
   if  [ -f /service/scripts/a ];then
       action "apache stop." /bin/true
       sleep 1
        rm -rf /service/scripts/a
         else
       action "apache stop." /bin/false
       sleep 1
   fi
;;
restart)
   if  [ -f /service/scripts/a ];then
     action "apache stop." /bin/true
     rm -rf /service/scripts/a
     sleep 1
     action "apache start." /bin/true
     touch /service/scripts/a
   else
     action "apache stop." /bin/false
     sleep 1
    action "apache start" /bin/true
     touch /service/scripts/a
   fi
;;
*)
   echo "Usage argument {start|stop|restart}"
esac
~                                                                                                                                          3   tomcat启动脚本               

#!/bin/bash
. /etc/init.d/functions
path="/usr/tomcat/tomcat8082/bin"
pp=`ps -ef | grep tomcat8082 | grep -v grep | wc -l`
Uid=`ps -ef |grep tomcat8082| grep -v grep | awk '{print $2}'`
start () {
   if  [  "$pp" -eq 0 ];then
      echo "start ..."
      action  "starting tomcat..."  /bin/true
      $path/startup.sh > /dev/null 2>&1
      sleep 1
   else
      action  "starting tomcat..."  /bin/true
   fi
}

stop () {
       if [ "$pp" -eq "0" ];then
              action "stopping tomcat" /bin/false
         else
              echo "stop ..."
              $path/shutdown.sh > /dev/null 2>&1
            if [ "$Uid" -ne "0" ];then
                pkill -9 $Uid
            fi
              sleep 1
              action "stopping tomcat..." /bin/true
       fi
}


case "$1" in
start)
             start
;;
stop)
             stop
;;
restart)
             stop
             start
;;
*)
             echo "Usage:$0  [start|stop|restart]"
;;
esac
~