1984 – the techblog

(Hopefully) useful various sysadmin and other stuff.

BSD watch (or: poor man’s GNU watch)

On GNU, there’s a neat com­mand to keep an eye on arbi­trary com­mands. It’s very use­ful when a fel­low sysad­min needs to mon­i­tor some­thing else than log files, or trace binaries.

Naïve as I am, I tried to use this on a FreeBSD sys­tem as well, only to dis­cover that the default watch com­mand does some­thing com­pletely dif­fer­ent 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 admin­is­tra­tor of this sys­tem (or hav­ing made this com­mand avail­able is out of the ques­tion 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 out­put of your_command every 2 sec­onds (Adjust as nec­es­sary). The tput is an ele­gant solu­tion to pre­vent your ter­mi­nal log get­ting fouled up by count­less clear‘s: Often, espe­cially when work­ing remotely, a clear doesn’t really clear the screen, instead, it just out­puts as many blank lines as your ter­mi­nal has. Hooray for scrolling. :| The tput instead will set your cur­sor back to the upper left cor­ner, effec­tively let­ting the com­mand over­writ­ing the pre­vi­ous out­put. Note that depend­ing on your ter­mi­nal, you may need to use a dif­fer­ent com­mand than cm 0 0. That whole ter­minfo stuff, unfor­tu­nately, is a fine mess of legacy hard­ware and con­cepts, lazy hard­ware design­ers and soft­ware devel­op­ers, as well busi­ness con­straints and focus on quick money. But that’s a tale for another post.


  1. http://www.freshports.org/sysutils/cmdwatch

Leave a Reply