服务检测是否正常运行的shell脚本

判断mysql服务是否正常启动
##############################################
#
# Author: yangxin - 934059036@qq.com
#
# QQ : 934059036
#
# Last modified: 2017-10-24 15:38
#
# Filename: Check_Mysql_Server.sh
#!/bin/sh
 PORT=`netstat -lnt | grep 3306 | wc -l `
Check_Mysql_Server()
{
   
    if [ $PORT -eq 1 ]
     then
        echo "mysql is running"
    else
        echo "mysql is not running"
        echo "progrome reeady to start mysql "
        sudo service mysql start
    fi
}
Check_Mysql_Server
检测ddos攻击
#!/bin/sh
netstat -an|grep SYN_RECV|awk '{print$5}'|awk -F: '{print$1}'|sort|uniq -c|sort -rn|awk '{if ($1>5) print $2}' >/tmp/dropip
for i in $(cat /tmp/dropip)
do
/sbin/iptables -I INPUT -s $i -j DROP
echo "$1 kill at `date`" >> /var/log/ddos
done
 
NGINX服务检查脚本 手动输入url判断
#!/bin/sh  
[ -f /etc/init.d/functions ]&&  source /etc/init.d/functions||exit 1
if [ $# -ne 1 ];then
   echo "Usage:$0 ip"
   exit
fi
http_Code=`curl -I -s  $1|head -1|cut -d " " -f2`
if [ "$http_Code" == "200" ];then
   action "nginx is running." /bin/true
else
   action "nginx is not running." /bin/false
sleep 1
   /application/nginx/sbin/nginx
fi
检测nginx服务
#!/bin/sh
LogPath=/application/tools/nginx-1.12.1/logs/access.log
web_PORT=`netstat -lnt|grep 80|wc -l`
web_Process=`ps -ef|grep nginx | grep -v grep |wc -l`
if [ $web_PORT -eq 1 ]&&[ $web_Process -eq 2 ];then
   echo "web is running"
else
 # nginx
   sleep 3
   web_PORT=`netstat -lnt|grep 80|wc -l`
   web_Process=`ps -ef|grep nginx | grep -v grep |wc -l`
   if [ $web_PORT -ne 1 ]&&[ $web_Process -ne 2 ];then
   while true
   do
       pkill nginx >/dev/null 2>&1
       sleep 1
      [ "$?" == "0" ] && break
      sleep 1    
  done
   nginx&&status="successful"||status="failure"
   #mail -s "web startup status is $status" 934059036@qq.com <$LogPath 
   echo "web is $status start"
  fi
fi

 

posted @ 2020-05-07 14:15  象飞田  阅读(656)  评论(0编辑  收藏  举报