Netstat continuous refresh (watch changes the output)
I am using this simple command to monitor connections (to deal with some recent DOS attacks) on my Debian server:
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
How do I run it continuously? So it will refresh itself once per minute (or any given amount of time, of course). I tried watch:
watch -n 30 "netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n"
But it changed the output from nice list with num of connections to smth like this:
1 tcp 0 10015 [LOCAL IP]
...
1 Proto Recv-Q Send-Q Local Address Foreign Address State
1 Active Internet connections (w/o servers)
So external IP is not being displayed… Is there’s something I missed?
EDIT: This is how the original output looks:
2 [IP ADDRESS]
4 [IP ADDRESS]
4 [IP ADDRESS]
4 [IP ADDRESS]
7 [IP ADDRESS]
16 [IP ADDRESS]
71 [IP ADDRESS]
And when I say [LOCAL IP] – I mean my machine’s IP.
EDIT 2: Forgot to add – it just freezes when I run it with -c.
netstat -c
may help you if i’ve not misunderstood your problem. -c stands for –continuous.
EDIT:
there you go:
watch -n 30 "netstat -ntu | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n"
I’ve added a \ before $.
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
- What is the easiest way to upgrade my existing Perl 5.14 to Perl 5.16 on FreeBSD 9 using the ports system?
- Know if mysql has done its job
- Redirect https .com to https .co.uk without a valid SSL cert on .com without DNS change
- Why is it a bad idea to use customer email as from address
- 100% packets dropped on first RX queue on 3/5 raid6 iSCSI NAS devices using intel igb (resolved)
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





