combine grep with the watch and netstat command

For the grep you need:

"grep gateway\|MultiMedia"

So perhaps try:

watch -n1 'netstat -upnlt | grep "gateway\|MultiMedia"'

I had a similar problem monitoring an ssh connection.

> netstat -tulpan|grep ssh
tcp        0      0 192.168.2.52:58072     192.168.2.1:22          ESTABLISHED 31447/ssh 

However watch -n 1 'netstat -tulpan|grep ssh' shows no output (apart from message from watch). If I change it to watch -n 1 'netstat -tulpan|grep ":22"' I get the required output line. It seems as if the -p option is ignored when netstat is run through watch. Strange.


There's also the new way of doing things... grep -E is nice and portable (Or egrep, which is simply quick for grep -E on linux&bsd) so you don't have to escape the quote. From the man pages:

-E Interpret pattern as an extended regular expression (i.e. force grep to behave as egrep).

So...

watch "netstat -upnlt | grep -E 'gateway|multimedia'"

or

watch "netstat -upnlt | egrep 'gateway|multimedia'"

Tags:

Grep

Watch