tcp状态监控脚本
#!/bin/bash
#********************************************************************
# File Name: tcp.sh
# Version: V1.0
# Author: dahuangji
# Email:
# Created Time : 2022-02-19 00:55:21
# Description:
#********************************************************************
RED='\E[31;1m'
GREEN='\E[32;1m'
END='\E[0m'
tcp_state() {
tcp_st=$1
if [[ "$tcp_st" = "" ]];then
echo -e "$RED必须给定统计tcp状态(大小写不敏感) $END"
echo "----------------------------------"
echo "用法: $0 状态"
echo "示例: $0 estab"
return 1
fi
ss -ant|awk 'NR>1{print $1}'|sort|uniq -c > /tmp/tcps
state_num=`grep -i "$tcp_st" /tmp/tcps|awk '{print $1}'`
[ -z $state_num ] && echo 0 || echo $state_num
}
tcp_state $1