#!/bin/bash
#this script is used to get TCP and UDP connetion status
#tcp status
Metric=$1
Tmp_file=/tmp/tcp_status.txt
Touch $tmp _file
Chown Zabbix. $tmp _file
/usr/bin/netstat-an|awk '/^tcp/{++s[$NF]}end{for (A in S) print A,s[a]} ' > $tmp _file
Case $metric in
Closed
output=$ (awk '/closed/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Listen
output=$ (awk '/listen/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
SYNRECV)
output=$ (awk '/syn_recv/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Synsent)
output=$ (awk '/syn_sent/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Established)
output=$ (awk '/established/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
timewait)
output=$ (awk '/time_wait/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Closing
output=$ (awk '/closing/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
closewait)
output=$ (awk '/close_wait/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
Lastack)
output=$ (awk '/last_ack/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
FINWAIT1)
output=$ (awk '/fin_wait1/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
FINWAIT2)
output=$ (awk '/fin_wait2/{print ' $tmp _file)
If ["$output" = = ""];then
Echo 0
Else
Echo $output
Fi
;;
*)
Echo-e "\e[033musage:sh [closed|closing|closewait|synrecv|synsent|finwait1|finwait2|listen|established|lastack |timewait]\e[0m "
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.