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?
syntax error near unexpected token done– Artem Russakovskii Mar 01 '18 at 17:31uberwatch 2 "date; ls" bash: date; ls: command not found– Artem Russakovskii Mar 03 '18 at 18:54while true; do date; ls; sleep 2; doneworks. – Artem Russakovskii Mar 03 '18 at 18:55${@:2}is encapsulated with double quotes, your command is run like so:while true; do "date; ls"; sleep 2; donewhich gives the same error you get. If you want to run more than 1 command, I'd recommend putting those inside a separate script, and call that script with theuberwatchfunction. Such as:uberwatch 2 /path/to/the/custom/script– Dan Mar 05 '18 at 15:37