Programmatically run background tasks in a split screen

gnu-screen

I'm trying to figure out how to create a command called runbg that will accept sub-commands to run in the background and create a split screen for each sub-command. When a sub-command completes successfully, the split screen is closed; if a sub-command fails, then the screen stays open with the error until the user closes the screen with the terminate signal. Once all screens are closed, the command is complete and execution continues. E.g.

runbg "ping -t 5 google.com" "ping -t 10 microsoft.com"
echo "done"

I've discovered I can do:

ping -t 5 google.com &
ping -t 10 microsoft.com &
wait

Which accomplishes the parallel side of things, however each command outputs everything to the same terminal, which is very noisy. Hence the desire for a split screen setup.

From searching here, I've discovered GNU Screen which seems to handle the screen side of things, but it seems it requires a .screenrc file – which while possible to do programmatically, is a bit annoying, as I'd imagine it would mean I would need to write a random tmp file somewhere.

I found this answer which goes into using screen without the .sreenrc however I cannot figure out how to do the split screen stuff in it.

So in short:

  • Is there something that already does the functionality that I'm aiming for with runbg?
  • If not, is GNU Screen what I want for this? Do I need to use a .screenrc file, or is there a way to accomplish the split screens without one?

Best Answer

You can do it with tmux by stringing together split-window and send-keys like this:

tmux new session \; split-window -v \; send-keys 'ping -t 5 google.com' C-m \; split-window -h \; send-keys 'ping -t 10 microsoft.com' C-m \;
Related Question