Getting the Linux "watch" command functionality on AIX
brian_s 270002K5X3 Comment (1) Visits (8628)
Linux has a very handy utility named "watch". It is a very useful command that will repeatedly run the same command over and over at a specified interval (by default, 2 seconds) and clear the screen in between each run. This is very useful when you want to "watch" something like what is in a directory (to watch files growing or changing), or to "watch" processes running (like "ps -ef | grep someuser").
For example, on Linux you can run:
And your screen will update every 2 seconds with a list of processes that contain "someuser".
AIX includes a command named "watch", however this command is completely unrelated to the Linux watch functionality. On AIX, watch is a command related to the auditing subsystem.
Fortunately, it is easy to write a one-line script that provides the basic functionality of the Linux "watch" on AIX:
This simple one-liner creates an infinite loop (while true); displays the date/time, runs whatever command you want to repeat (in this example, ps -ef | grep someuser), then sleeps for 1 second (you can change this to whatever amount you would like), and then clears the screen and repeats. If you want to exit the loop, just hit CTRL-C. This one line implements the basic functionality of the Linux watch command.
The native Linux watch command provides some additional functionality and optional fancy features like highlighting the text that changes between screen refreshes. If you want a fully functional watch command on AIX, check out Michael Perzl's awesome website of open source packages for AIX, which includes "watch": http