Skip to content

Instantly share code, notes, and snippets.

@hartfordfive
Created February 24, 2016 15:33
Show Gist options
  • Select an option

  • Save hartfordfive/461aecd220eeb3efe79b to your computer and use it in GitHub Desktop.

Select an option

Save hartfordfive/461aecd220eeb3efe79b to your computer and use it in GitHub Desktop.
Get total number of active and closing connections for a given port
!/bin/bash
PORT=$1
if [ "$PORT" == "" ]; then
echo "Usage: $0 [PORT]"
exit 1
fi
while [ true ]
do
clear
CONNS=$(netstat -tulpna | grep :$PORT)
ACTIVE=$(echo "$CONNS" | grep ESTABLISHED)
CLOSING=$(echo "$CONNS" | grep FIN_WAIT)
echo "Total connections:"
echo "$CONNS" | wc -l
echo "Total connections active:"
echo "$ACTIVE" | wc -l
echo "Total closing:"
echo "$CLOSING" | wc -l
sleep 2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment