UNIX Utility of the Day: watch

by Bob Plankers on April 26, 2011 · 1 comment

in System Administration,Virtualization

Not a lot of people know about the ‘watch’ command, part of the standard complement of GNU tools available on most Linux distributions, as well as many Linux-like OSes such as VMware ESX and the VMware vMA.

Simply put, it runs a command at a specific interval for you. So if you want to continually see the number of httpd processes running on a host you could use:

watch 'ps -ef | grep httpd | wc -l"

Or maybe you want to watch the temperature on a remote physical host using IPMI. The -n flag changes the number of seconds between the commands:

watch -n 60 -d 'ipmitool -I lan -U username -P password -H host-bmc.address sdr type "Temperature"'

The -d or —differences flag seen above will make it highlight changes. There’s also —differences=cumulative, which makes the differences highlighting sticky, and options to turn off the title & header:

watch -n 1 --d=cumulative -t 'sudo ls -la /var/run'

It’s a simple command, but very useful, and as is usually the case a ‘man watch’ on your host will likely have the rundown on all the parameters, as well as more examples.

{ 1 comment }

Comments on this entry are closed.

Previous post:

Next post: