Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace netstat with ss to implement the low level discovery for zabbix
#!/bin/bash
lines=$(sudo ss -lp | grep $1 | awk '{print $3}' | cut -d: -f2 | sort | wc -l)
if [ "$1" == "mongod" ]
then
portarray=(`sudo ss -lp | grep $1 | awk '{print $3}' | cut -d: -f2 | sort | head -n $(($lines/2)) 2>/dev/null`)
else
portarray=(`sudo ss -lp | grep $1 | awk '{print $3}' | cut -d: -f2 | sort 2>/dev/null`)
fi
length=${#portarray[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
printf '\n\t\t{ '
printf "\"{#TCP_PORT}\":\"${portarray[$i]}\" }"
if [ $i -lt $[$length-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
@huangjunque

This comment has been minimized.

Copy link

huangjunque commented Jan 5, 2016

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment