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
posted @ 2020-12-24 10:37  Eddie·Peng  阅读(265)  评论(0编辑  收藏  举报