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     ESTABLISHED
tcp        0   0     ESTABLISHED
tcp        0   0     ESTABLISHED
udp        0   0 *:ibm-db2                   *:*

which is nice :-)

No comments:

TIL - read-only variables in Linux

 A co-worker was seeing an exception: -  line 8: TMOUT: readonly variable when trying to SCP a file from a remote Linux box. I did some digg...