tcp状态统计脚本
tcp_status_ss.sh #!/bin/bash #scripts for tcp status function SYNRECV { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'SYN-RECV' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function ESTAB { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'ESTAB' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function FINWAIT1 { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'FIN-WAIT-1' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function FINWAIT2 { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'FIN-WAIT-2' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function TIMEWAIT { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'TIME-WAIT' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function LASTACK { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'LAST-ACK' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function LISTEN { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'LISTEN' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function CLOSE-WAIT { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'CLOSE-WAIT' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function CLOSING { n=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'CLOSING' | awk '{print $2}'` if [ "x$n" == "x" ]; then echo 0; else echo $n; fi } function ALL { /usr/sbin/ss -ant | wc -l } $1