zoukankan      html  css  js  c++  java
  • Linux 检查端口gps命令

    由于是游戏业务,环境主要是Nginx+Tomcat+Java Program

    gps脚本环境以及效果图如下:

    #!/bin/bash
    
    function Printf (){
        if [ $1 == 1 ];then
            printf '%-50s
    ' "+-----------------+------------------+-----------------+"
            shift 1
        fi
        printf '%1s %-10s %1s %10s  %1s %10s %1s
    ' "|"  "$1"  "|" "$2" "|" "$3" "|"
        printf '%-50s
    ' "+-----------------+------------------+-----------------+"
    }
    
    function GameStatus (){
        Port=$1
        Path=$2
        Name=$3
        local SiteValue=$4
        Ppid=$5
        nc -vz 127.0.0.1 ${Port} >/dev/null 2>&1
        if [ $? == 0 ];then
            Status=$(echo -e "e[32m OK  e[0m")
        else
            Status=$(echo -e "e[31mErrore[0m")
        fi
        if [[ -z ${Ppid} ]];then
            if [ "$USER" == "root" ];then
                Pid=$(netstat -nltp | egrep -w "0.0.0.0:${Port}|0 :::${Port}" | awk '{print $7}' | sed 's#/.*##')
            else
                Pid=$(sudo netstat -nltp | egrep -w "0.0.0.0:${Port}|0 :::${Port}" | awk '{print $7}' | sed 's#/.*##')
            fi
        else
            Pid=$(ps -ef | grep -i "${Path}/" |grep -i "${Name}/" |grep -v "grep" | awk '{print $2}')
        fi
        printf '%-20s %-6s %-15s %-12s %-25s %-6s %-15s
    ' "${Date}" "${Pid}" "${Name}" "${SiteValue}" "${Path}" "${Port}" "Status:[${Status}]"
    }
    
    function GameCheck (){
        GamePath=(/ccu/server /usr/local/tomcat /data/dandantang)
        GsPort=(8004 8080 9200)
        GameStatus 80 /usr/local/nginx Nginx " "
        echo -e "e[35m--------------------------------------------------------------------------------------------------------------------------------------------e[0m"
        for (( i=0;i<3;i++ ))
        do
            GameStatus ${GsPort[$i]} ${GamePath[$i]} GameServer
        echo -e "e[35m--------------------------------------------------------------------------------------------------------------------------------------------e[0m"
        done
    }
    
    Online_check(){
        echo -e "e[35m-------------------------- Online Info.  ----------------------------e[0m"
        local Ports="9200 9300"
        local Sum_online=0
        for Port in $Ports
        do
            local Port_online=`netstat -ntp|awk -v a=0 
                '/ESTABLISHED/&&$4~":'$Port'"{a+=1}END{print a}'`
            Sum_online=$(($Sum_online + $Port_online))
            case $Port in
                9200)
                    Port_name="Gameserver1_port(9200):"
                    ;;
                9300)
                    Port_name="Gameserver2_port(9300):"
                    ;;
            esac
            printf "%-25s%14s
    " "$Port_name" "$Port_online"
        done
    
        printf "%-25s%14s
    " "Gameonline:" "$Sum_online"
    }
    
    Date=`date '+[%Y-%m-%d %H:%M:%S]'`
    echo "Main Site:$(hostname)"
    echo -e "e[35m--------------------------------------------------------------------------------------------------------------------------------------------e[0m"
    GameCheck
    Online_check
    gps

  • 相关阅读:
    hdu 5504 GT and sequence
    解决:Incorrect line ending: found carriage return ( ) without corresponding newline ( )
    hdu 5501 The Highest Mark(贪心+01背包)
    web开发学习之路是否有尽头
    2016年后web开发趋势是什么?
    使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录
    web开发微信文章目录
    现代web开发需要学习的15大技术
    移动前端重构实战系列
    什么鬼,又不知道怎么命名class了
  • 原文地址:https://www.cnblogs.com/Mrhuangrui/p/6419928.html
Copyright © 2011-2022 走看看