Wednesday, January 9, 2019

watch

Have you ever wanted to run some command periodically, usually to wait for some change in the result (like waiting for some ACL to be propagated, a price value to change, etc)?

Seek no more! Do you know the "watch" unix command?
watch -n 60 <command>
This will run <command> every 60 seconds! And you can inspect the output every time it does.

Its usage is quite simple. The help output is:

Usage:
 watch [options] command

Options:
  -b, --beep             beep if command has a non-zero exit
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates
  -p, --precise          attempt run command in precise intervals
  -t, --no-title         turn off header
  -x, --exec             pass command to exec instead of "sh -c"

 -h, --help     display this help and exit
 -v, --version  output version information and exit

Useful command to know!