3

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?
1
  • Depending on what terminal emulator you are using, you can spawn new instances of it with options to do what you want. mate-terminal does this
    – ivanivan
    Apr 11, 2017 at 3:46

1 Answer 1

4

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 \;
1
  • 2
    This worked great. I went and built github.com/balupton/dotfiles/blob/… with it - which also auto-closes a window on success. Usage like together 'ping -t 5 google.com' 'ping -t 10 microsoft.com'
    – balupton
    Apr 11, 2017 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .