Linux 检查端口gps命令

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

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

#!/bin/bash

function Printf (){
if [ $ == ];then
printf '%-50s\n' "+-----------------+------------------+-----------------+"
shift
fi
printf '%1s %-10s %1s %10s %1s %10s %1s\n' "|" "$1" "|" "$2" "|" "$3" "|"
printf '%-50s\n' "+-----------------+------------------+-----------------+"
} function GameStatus (){
Port=$
Path=$
Name=$
local SiteValue=$
Ppid=$
nc -vz 127.0.0.1 ${Port} >/dev/null >&
if [ $? == ];then
Status=$(echo -e "\e[32m OK \e[0m")
else
Status=$(echo -e "\e[31mError\e[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\n' "${Date}" "${Pid}" "${Name}" "${SiteValue}" "${Path}" "${Port}" "Status:[${Status}]"
} function GameCheck (){
GamePath=(/ccu/server /usr/local/tomcat /data/dandantang)
GsPort=( )
GameStatus /usr/local/nginx Nginx " "
echo -e "\e[35m--------------------------------------------------------------------------------------------------------------------------------------------\e[0m"
for (( i=;i<;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=
for Port in $Ports
do
local Port_online=`netstat -ntp|awk -v a= \
'/ESTABLISHED/&&$4~":'$Port'"{a+=1}END{print a}'`
Sum_online=$(($Sum_online + $Port_online))
case $Port in
)
Port_name="Gameserver1_port(9200):"
;;
)
Port_name="Gameserver2_port(9300):"
;;
esac
printf "%-25s%14s\n" "$Port_name" "$Port_online"
done printf "%-25s%14s\n" "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

Linux 检查端口gps命令

上一篇:异步执行js脚本——防止阻塞


下一篇:神秘的 shadow-dom 浅析