Last active
February 23, 2018 08:13
-
-
Save laszlomiklosik/9761903 to your computer and use it in GitHub Desktop.
Linux monitor the number of connections on a given port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# below example is a shell script which logs the number of connections every 30 seconds | |
#!/bin/bash | |
if [ "$#" -ne 1 ]; then | |
echo "Please provide the port number for which you want to monitor the connection count as the one and only argument!" | |
exit | |
fi | |
while true; do | |
crtDate=`date` | |
crtConnectionCount=`netstat -a -n | grep "$1" | grep ESTABLISHED | wc -l` | |
crtLine="$crtDate Connection count: $crtConnectionCount" | |
echo $crtLine >> connections_port_$1.txt | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An even better script: