GNU watch without erasing previous outputs

gnu watch is a very useful tool for inspecting a program output: It executes the program and shows the output full-screen every 2 seconds.

Sometimes, I don't want the previous output to be erased, but rather be printed line by line with a time stamp. For that, I use bash scripts like:

while true; 
    do echo -n "`date`   "; 
    ssh ubuntu@server -o ConnectTimeout=1 "uptime" ; 
    sleep 1; 
done

Is there a watch-like tool that can run a command and display its output with a timestamp in a line without erasing previous output?


I'd say you've found it in simple loops but you could do a number of things from here:

Write a function to handle that for you

function uberwatch {
    # call: uberwatch <interval> <command>
    while true; do
        "${@:2}";
        sleep $1;
    done
}

You could lodge that somewhere around your ~/.bashrc.

Log the output to file but keep viewing with watch

watch ... "command | tee -a watchlog.log"

You'd still only see the latest run-through but you could dig through a historical log if you needed to.