I'd like to run a few commands simultaneously and observe their output in real-time. Ideally it would be an automatic bash script which runs commands c1
, c2
, c3
at the same time and shows them in a grid view in a single terminal.
How can I achieve that the easiest way?
I've seen that screen
could do something like that, but I'm not sure how to put that together. I'm using KDE Plasma, so I suppose I need to run that script with konsole
. The commands are not always the same, so I need to parametrize them.
答案1
Very simplest:
ESSENTIAL First, BASIC requirement:
Make sure each command does a SINGLE quick update, prints the result and EXITS after that.
Create a text file with this content, save as e.g. observer.sh
rev="$(tput rev)" off="$(tput sgr0)" while true ; do tput reset; date; echo -e "$rev--- c1 ---$off"; # command c1 here echo -e "$rev--- c2 ---$off"; # command c2 here echo -e "$rev--- c3 ---$off"; # command c3 here sleep 1; done
Start it with bash observer.sh
The script, as is above, shows a rolling date/time at top, 1 second update.
To get the output in "a grid" is quite a bit harder; it involves manipulating the output window with e.g. ncurses commands via e.g. tput
AND setting and retaining stdin, stdout and stderr for each command connected to each a separate ncurses-window - similar to what Bash does as it starts a command.
Note: https://stackoverflow.com/q/47502223/3720510 indicates that this isn't an easy task
But then: https://github.com/metal3d/bashsimplecurses
Simple examples: https://www.youtube.com/watch?v=MEULy6oqrfM