28.11. Repeating a Time-Varying CommandGo to http://examples.oreilly.com/upt3 for more information on: vis Sometimes you find yourself repeating the same command over and over again -- for example, ps (Section 24.5) to monitor the progress of your background processes, or lpq (Section 45.2) to know when your printout is finished. Instead of typing the same command repeatedly, or even using shell history (Section 30.2) to repeat it, use the vis command. For example: % vis ps The vis command takes over your screen and shows the output of the initial ps command. Every 15 seconds, the command is executed again and your screen is updated with the new information. If this delay is too long for you, you can get vis to use a shorter delay using the -d option: % vis -d 2 ps The information will now be updated every 2 seconds. Your screen is cleared and you are shown the output of ps. On the top line, vis tells you the command being run, how long your delay is (if not the default), and how many times it has been executed. The Exec: line is incremented every time the command is repeated. Command: ps Delay: 2 Exec: 1 PID TT STAT TIME COMMAND 2971 p1 S 0:06 -sh (csh) 6139 p1 S 0:00 vis -d 2 ps 6145 p1 R 0:00 ps 3401 q0 IW 0:13 -sh (csh) 5954 q0 S 0:01 vi ch01 14019 q5 IW 0:02 -sh (csh) 29380 r7 IW 0:00 -bin/csh (csh) 29401 rd IW 0:00 -bin/csh (csh) vis provides a few other command-line options. The -s option is particularly neat: using -s, any lines that have changed since the last iteration are printed in standout mode. Note that variations of this command have floated around in the public domain under several different names, such as display, rep, and watch. We found vis to be the most useful. -- LM Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|