combine grep with the watch and netstat command

ant2009 picture ant2009 · Sep 27, 2012 · Viewed 21.2k times · Source

Red Hat Enterprise Linux Server release 5.4 (Tikanga) 2.6.18-164.el5

I am trying to use the watch command combined with the netstat to see the 2 programs using certain ports.

However, with the command I using below doesn't work for both words:

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

Is this the correct way to grep for both program names.

If I use one its ok, but both together doesn't work.

Answer

Bitwise picture Bitwise · Sep 27, 2012

For the grep you need:

"grep gateway\|MultiMedia"

So perhaps try:

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