BSD watch (or: poor man’s GNU watch)
On GNU, there’s a neat command to keep an eye on arbitrary commands. It’s very useful when a fellow sysadmin needs to monitor something else than log files, or trace binaries.
NaÃ¯ve as I am, I tried to use this on a FreeBSD system as well, only to discover that the default
watch command does something completely different on BSD’s: it snoops ttys. GNU
watch can be used on FreeBSD as well by installing the a port 1, but what if you’re not the administrator of this system (or having made this command available is out of the question for some other reasons)?
Just use this:
clear; while true ; do <your_command> ; sleep 2 ; tput cm 0 0 ; done
This clears the screen once, and from then on, shows the output of
your_commandÂ every 2 seconds (Adjust as necessary). The
tput is an elegant solution to prevent your terminal log getting fouled up by countless
clear‘s: Often, especially when working remotely, a
clearÂ doesn’t really clear the screen, instead, it just outputs as many blank lines as your terminal has. Hooray for scrolling. The
tput instead will set your cursor back to the upper left corner, effectively letting the command overwriting the previous output. Note that depending on your terminal, you may need to use a different command than
cm 0 0. That whole terminfo stuff, unfortunately, is a fine mess of legacy hardware and concepts, lazy hardware designers and software developers, as well business constraints and focus on quick money. But that’s a tale for another post.
- http://www.freshports.org/sysutils/cmdwatch ↩