watch

Have you ever wanted to keep trying a command over and over and not be bothered until something about it changes? (Ping my server until it’s responding.) Or to take a one-shot stdin/stdout program like who or last and just watch it over time? There’s a utility for that: watch.

Watch is a utility from the procps-ng project. Watch command basically turns a stdin/stdout program command into a heads-up curses program. So, if you for instance ran

watch ps

you would get a heads-up screen with the first page’s worth of the output of ps, updated every two seconds. (Note this means that a new copy of ps will be run every two seconds.)

The options it takes are as follows:

-d Highlight the differences between iterations

-n <num> Specify the seconds between command invocations

-p Try to make the time between invocations be as precise as possible

-t Turn off the header information showing the command, delay, and current time

-b Beep if command exits with a value other than zero

-e Stop updating if the command returns an error

-g Exit if the command’s output changes (e.g. busy-loop until the host comes back up)

-c Interpret ANSI color sequences from the output of command

-x Pass command to exec(2) rather than sh -c (pick your poison on the quoting rules there)

-h Display usage

-v Display version and exit

 

Leave a Reply

Your email address will not be published. Required fields are marked *