2

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 4x2 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

4
  • Do the utilities properly react to SIGWINCH? i.e. do they adjust their output to the terminal size dynamically? Or should one prepare terminals beforehand, then run the utilities and never resize? Commented Oct 29, 2021 at 13:55
  • no theres no automatic adjustment, the output is always fixed size Commented Oct 29, 2021 at 14:01
  • (1) "Fixed" like "hardcoded"? or "fixed" like "obtained when the utility starts and never updated"? What I need to know exactly: if you run the utility in a big terminal and later shrink the terminal to 1/8 of its original size, will the utility work as expected? (2) What layout do you want? 1 column of 8 rows? 1 row of 8 columns? 2 of 4? 4 of 2? 3 of 3 (with one pane unused)? Commented Oct 29, 2021 at 14:10
  • Basically most of them output a table created by console.table in js. So their size is entirely fixed by the amount of columns (4-5) in that table. So since I'll be running it in full screen most of the time, I thought the layout that made the most sense was 4x2 Commented Oct 29, 2021 at 14:24

1 Answer 1

4

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
1

You must log in to answer this question.

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