Skip to content

Instantly share code, notes, and snippets.

@qosmio
Created June 8, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qosmio/6a054b60a53f3e2b7f0cc678a2c10ee3 to your computer and use it in GitHub Desktop.
Save qosmio/6a054b60a53f3e2b7f0cc678a2c10ee3 to your computer and use it in GitHub Desktop.
#!/bin/bash
PORT=62419
OUTFILE=/tmp/db2_was.log
SLEEP=30
echo " TIMESTAMP | PRT | CONNECTION_STATES"
echo "------------------------ ------ ---------------------------------------------------"
while true
do
netstat -ant | grep -v grep |grep $PORT|
awk -v port=$PORT -v date=" $(date +"%Y-%m-%d %r")" '
/SYN_SEND|SYN_RECEIVED|ESTABLISHED|LISTEN|FIN_WAIT_1|TIMED_WAIT|CLOSE_WAIT|FIN_WAIT_2|LAST_ACK|CLOSED/ {
count[$6]++
} END {
printf date" | "port" |@";
for(s in count) {
printf("%12s:%6d,", s, count[s]);
}
}'|LANG=C perl -pe "s/,$/\n/g;s/\s{2,}//g|s/@/ /g"
sleep $SLEEP | tee -a $OUTFILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment