zabbix监控Linux系统tcp连接状态的shell脚本

#!/bin/bash
tcp_conn_status(){
    TCP_STAT=$1
    ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' > /tmp/tcp_conn.txt
    TCP_NUM=$(grep "$TCP_STAT" /tmp/tcp_conn.txt | cut -d ' ' -f2)
    if [ -z $TCP_NUM ];then
        TCP_NUM=0
    fi
    echo $TCP_NUM
}

main(){
    case $1 in
        tcp_status)
            tcp_conn_status $2;
            ;;
        *)
            echo $"Usage: $0 {tcp_status key}"
    esac
}
main $1 $2
原文地址:https://www.cnblogs.com/eddie1127/p/14182921.html