• 服务检测是否正常运行的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
    
  • 相关阅读:
    XAML实例教程系列
    XAML实例教程系列
    XAML实例教程系列
    正则表达式 修改流程 过程是崎岖的
    Codeforces Round #379 (Div. 2) 解题报告
    (DFS)codevs1004-四子连棋
    (BFS)poj2935-Basic Wall Maze
    (BFS)poj1465-Multiple
    (BFS)uva2554-Snakes & Ladders
    (BFS)hdoj2377-Bus Pass
  • 原文地址:https://www.cnblogs.com/shanghai1918/p/12842732.html
Copyright © 2020-2023  润新知