Using watch to monitor other commands periodically

24 August 2016

Lately I’ve been doing a lot of hardware diagnostic tasks. One of which was to monitor network connection over screwed (and then repaired) twisted pair cable. I found myself constantly hitting to call ip l show eth0 again. And then I thought…

Use the loop

Something simple enough like

while true; do ip l show eth0; sleep 1; done

would do. Luckily, on the morning I’ve read about one useful utility called watch.

watch

It does essentially the same, plus it has some nice features like:

So the command above would look like

watch -n 1 -d ip l show eth0

and it also would highlight the line eth0 <NO-CARRIER BROADCAST...> eth0 <BROADCAST ...> with inverse color when it changes, so it becomes quite noticeable when the link is lost.