Is there a paging version of `watch`?

8,703

Solution 1

Rather than modifying the 'watch' command, use screen!

For example, let's say that you need to be able to see 300 lines of height and 100 characters of width and move around that. After starting screen, force the size thus:

C-a :height -w 300
C-a :width -w 100

Now start your watch command. You can then use C-a <ESC> to page around the display.

Unfortunately, the display doesn't refresh while in copy mode. But if you want to adjust which section of the window you're viewing, the easiest way may be to rerun the height/width commands as by default your terminal shows the lower-right of the virtual window.

Solution 2

You can try this:

$ while vmstat; do sleep 1; done | less

replace vmstat with qstat and adjust the sleep to your needs.

Solution 3

Multitail: http://www.vanheusden.com/multitail/

Example:

 vmstat 1 |multitail -j

Scroll back by press 'b' and page/arrow up/down.

Solution 4

OK, I've had a little go at a watchless function. It's a bit rough, and it doesn't yet appear to completely work, but here goes:

#!/bin/bash -u
out=$(mktemp)
(while [ 1 ]; do
    "$@" > $out;
    sleep 2;
done) &
less $out
kill $!

You have to manually use the R key in less to get the display to update.

It appears to work for watchless date but not for watchless qstat or watchless pstree, which both show blank. Any ideas?

Share:
8,703

Related videos on Youtube

David Dean
Author by

David Dean

Updated on September 17, 2022

Comments

  • David Dean
    David Dean almost 2 years

    Under a UNIX shell, how can I get a similar effect to the watch command, but with paging so that I can scroll around in the output if it takes up more than one screen?

    In other words, I want a program that is to watch what less is to cat.

    As an example, lets say I wanted to watch the output of qstat, I could use

    watch qstat
    

    to watch the output of qstat, but this can only shows the first screenful.

    With a paging version of watch, I would be able to move around in the output as it is still continuously updated by watch. Is there any way to do this at the moment with existing utilities?

  • David Dean
    David Dean almost 15 years
    all this does is keep repeating the command into less, which means that you need to keep scrolling to see the latest output.
  • Spacen Jasset
    Spacen Jasset almost 15 years
    Yes, but you can scroll back. You can't have both at once. Pressing shift f, that is capital 'F' will work like tail.
  • David Dean
    David Dean almost 15 years
    the only issue then is how to continually repeat the command, while blanking the screen between each go
  • Steve Townsend
    Steve Townsend almost 15 years
    Oops, I meant run the watch command inside screen. Fixed.
  • warren
    warren almost 15 years
    yartls - yet another reason to love screen :)
  • henry
    henry about 6 years
    note that C- is aka ctrl-
  • rymo
    rymo over 4 years
    Append +F to "pre-press" F and automatically follow: while vmstat; do sleep 1; done | less +F