Repeat a command every x seconds forever using watch

This is a command that we, sysadmins, use all day to see, with x seconds of refresh, live data.

There’s a built-in Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to refresh.

How you can do that?

Usage: watch [-dhntv] [–differences[=cumulative]] [–help]     [–interval=<n>]
[–no-title] [–version] <command>`

So, if you want to run a command each second(default is 2 sec) you can do the following:

# watch -n1 command

If you want to run this command on Mac OS X, you need to get watch from Mac Ports, or you can get it via Homebrew:

brew install watch

And that’s it.

Cheers

No Comments

Post a Comment