tmux – Run 8 Commands in Parallel in Equalized Panes

bashdisplayterminalterminal-multiplexertmux

I have a monitoring utility that consists of 8 individual utilities, to monitor multiple aspects of a system.
All of them kind of work like htop, in that they rewrite the screen periodically instead of exiting after they are run.

In order to make my life a little bit easier I thought it might be usefull to be able to create a script that I can run on a remote server that would open all of these commands up in a terminal multiplexer in some sort of sane way in equally sized panes (it would be nice if the stacking was automatically determined based on terminal size (ie 4×2 if viewed in full screen on a widescreen monitor, but not necessary).

Basically I want to be able to run 8 different commands simulataneously in different equally sized panes in a single terminal. I tried using tmux for this using the split-window argument, but that doesn't allow me to equally size the panes, since they are recursive and so the next pane is always half the size of the previous pane

Best Answer

Finally figured it out:

#!/bin/bash
# I'd love to add comments line by line but bash wont let me

tmux \
new-session \
'command 1'\; \
split-window \
'command 2'\; \
split-window -h \
'command 3'\; \
split-window \
'command 4'\; \
select-layout even-horizontal\; \
select-pane -t 0 \; \
split-window  -v \
'command 5'\; \
select-pane -t 2 \; \
split-window  -v \
'command 6'\; \
select-pane -t 4 \; \
split-window  -v \
'command 7'\; \
select-pane -t 6 \; \
split-window  -v \
'command 8'\; \

heres how it works:

  • create a new session with command1
  • create 3 new split windows with more commands
  • reorder those splits according to even-horizontal
  • select first pane again
  • split it in half, this time vertically
  • select second window we created, that because of the previous command now has index 2
  • same with the sixth split
  • and so on
Related Question