[root@SHCTC-GAME5-151 release1]# cat router-conn-chk.sh
#!/bin/bash
SSHD="/app/oslinkd/bin/ssh -T"
BASE_DIR=`pwd`
SRV_FILE="$BASE_DIR/serversdmz.txt"
SRV_LIST="$BASE_DIR/checklist.txt"
SRV_TYPE=`awk '!/^#/{print $1}' $SRV_LIST|egrep -i -v "router|profile|ue|pt|centercatalog|catalog"`
#for srv_type in tunnel logic hall market account gm pay ui dbcache act misc state rank task syn family ap
for srv_type in $SRV_TYPE
do
#/app/oslinkd/bin/ssh "netstat -anp|awk '\$5~/:5102[1-4]/&&/EST/{t++}'END'{printf "%d",t}'"
ALL_IP=`awk '!/(^#|mysql)/&&/\<'$srv_type'\>/{print $2}' $SRV_FILE`
for sip in $ALL_IP
do
fun_conn(){
conn_proc="`$SSHD $sip "$RCMD"`"
string=`echo $srv_type|awk -F- '{print $1}'`
statu_proc="`$SSHD $sip "ps aux|grep $string|grep dmz|grep -v grep"`"
if [ "$conn_proc" -eq 0 ] && [ -z "$statu_proc" ];then
#echo "Perhaps $srv_type process is not running. | `grep $srv_type $SRV_FILE|egrep -v "^#"`";
cmd=`grep "\<$srv_type\>" $SRV_FILE|egrep -v "^#"`
awk 'BEGIN{printf "%-43s","Perhaps '$srv_type' process is not running.";printf "\n"}'
else
mod=`expr $conn_proc % 4`;
case $mod in
0)
#echo "conn count: $conn_proc | `grep $srv_type $SRV_FILE|egrep -v "^#"`"
cmd=`grep "\<$srv_type\>" $SRV_FILE|egrep -v "^#"`
awk 'BEGIN{printf "%-12s","'$srv_type'";printf "%-16s","conn count: '$conn_proc'";printf "\n"}'
;;
*)
echo "Abnormal! | `grep $srv_type $SRV_FILE`"
;;
esac
fi
}
string=`echo $srv_type|awk -F- '{print $1}'`
if [ x"$string" = x"dbcache" ];then
RCMD="netstat -anp|awk '\$5~/:5102[1-4]/&&/EST/&&/(dmdb|frienddb|gamedb|itemdb|namedb|maildb)/'|grep -v conn|wc -l"
statu_proc="`$SSHD $sip "ps aux|egrep 'dmdb|frienddb|gamedb|itemdb|namedb|maildb'|grep dmz|grep -v grep"`"
fun_conn;
else
#判断连接数为4的整数倍正常;其他情况报异常.
RCMD="netstat -anp|awk '\$5~/:5102[1-4]/&&/EST/&&/'$string'/'|grep -v conn|wc -l"
fun_conn
fi
done
done
阅读(760) | 评论(0) | 转发(0) |