Thursday, 17 December 2015

Using watch to loop in Bash

I wanted to monitor a particular set of TCP/IP listeners, on an ongoing basis, and thought "I wonder how I do this?".

A quick Google led me here: -


specifically to the /usr/bin/watch command: -

       watch - execute a program periodically, showing output fullscreen

Here's my command: -

watch -n5 'netstat -a | grep db2'

which watches the output from the netstat command, and updates the display every 5 seconds, resulting in this: -

Every 5.0s: netstat -a | grep db2                                                                                                                                                   Thu Dec 17 13:29:07 2015

tcp        0   0 *:ibm-db2                   *:*                         LISTEN
tcp        0   0 bpm856.uk.ibm.com:39889     db2two.uk.ibm.com:60007     ESTABLISHED
tcp        0   0 bpm856.uk.ibm.com:39888     db2two.uk.ibm.com:60007     ESTABLISHED
tcp        0   0 bpm856.uk.ibm.com:39890     db2two.uk.ibm.com:60007     ESTABLISHED
udp        0   0 *:ibm-db2                   *:*


which is nice :-)

No comments: