I cannot split the terminal into 5 terminals (vertical or horizontal). I don't understand why the split crashes or does nothing every time I try to do it in the bash or screenrc script. I don't want to do the split with the keyboard shortcuts but directly in the executed files (split -v or split -h, or screen -X split -v).
script.sh
sudo podman network create podman
sudo podman login xxxxx
rabbitmq="docker.io/rabbitmq:latest"
podman1="xxxxx"
podman2="xxxxx"
podman3="xxxxx"
podman4="xxxxx"
sudo podman pull $rabbitmq $podman1 $podman2 $podman3 $podman4
sudo podman stop -i $rabbitmq $podman1 $podman2 $podman3 $podman4
SCREENS_TEST=$(sudo screen -ls | grep run_screen | wc -l)
if [ $SCREENS_TEST -eq 0 ]
then
sudo screen -m -dS run_screen -c .screenrc
else
sudo screen -S run_screen -X quit
sudo screen -m -dS run_screen -c .screenrc
fi
sudo screen -S run_screen -x -X screen -t rabbitmq bash -c "sudo podman run -it --rm --name rabbitmq --network podman --hostname rabbitmq -p 5672:5672 $rabbitmq"
sudo screen -S run_screen -x -X screen -t podman1 bash -c "sudo podman run --rm -it --env-file=attributs.env $podman1"
sudo screen -S run_screen -x -X screen -t podman2 bash -c "sudo podman run --rm -it --env-file=attributs.env $podman2"
sudo screen -S run_screen -x -X screen -t podman3 bash -c "sudo podman run -it --rm --env-file=attributs.env -p 8000:80 $podman3"
sudo screen -S run_screen -x -X screen -t podman4 bash -c "sleep 15 && sudo podman run -it --rm --env-file=attributs.env $podman4"
sudo screen -r run_screen
.screenrc
vbell off
scrollback 10000
term xterm-256color
nonblock 5
shell -${SHELL}
caption always "%3n %t%? @%u%?%? [%h]%?%=%c"
startup_message off
bind ' ' windowlist -b
You made a couple of mistakes. So it's not simple.
First, you didn't do any splits in your commands. Second, you send commands wrongly.
Let's make new.screenrc
.
Modify the screenrc's layout as what you like in the code.
layout save defaults
setting prevents losing layouts.
shell bash
makes bash the default shell.
# this setting prevents losing layouts.
layout save defaults
vbell off
scrollback 10000
term xterm-256color
nonblock 5
# this makes bash the default shell.
shell bash
caption always "%3n %t%? @%u%?%? [%h]%?%=%c"
startup_message off
bind ' ' windowlist -b
screen -t rabbitmq 1
screen -t podman1 2
screen -t podman2 3
screen -t podman3 4
screen -t podman4 5
# This is an example of a layout split setting.
# As you can see, it mimics the way you split windows interactively.
select rabbitmq
split
focus down
select podman1
split -v
focus right
select podman2
split
focus down
select podman3
split
focus down
select podman4
# with this setting, your screen will be detached.
# if you put this setting in front of the screenrc, the layout split setting won't work.
detach
This code has a con which is that the screenrc doesn't make a layout with -d -m
option. But there is a tactic to recover the layout.
But in an interactive shell, it works great.
^M
at the end of the commands you want to run does not consist of ^
and M
. This is the meta character ^M
, which you make by Ctrl-v
and RET
(RET is a return key or an enter key) or Ctrl-v
and Ctrl-m
. Without the character, the gnu screen read your command and doens't execute it because without the special character, the gnu screen won't type enter in the prompt.
But you can just use \r
instead of ^M
sudo screen -S run_screen -X at podman1 stuff "sudo podman run --rm -it --env-file=attributs.env $podman1\n"
I replace your commands which have -dm
option with mine.
The screenrc will detach the session.
sudo podman network create podman
sudo podman login xxxxx
rabbitmq="docker.io/rabbitmq:latest"
podman1="xxxxx"
podman2="xxxxx"
podman3="xxxxx"
podman4="xxxxx"
sudo podman pull $rabbitmq $podman1 $podman2 $podman3 $podman4
sudo podman stop -i $rabbitmq $podman1 $podman2 $podman3 $podman4
SCREENS_TEST=$(sudo screen -ls | grep run_screen | wc -l)
if [ $SCREENS_TEST -eq 0 ]
then
sudo screen -S run_screen -c new.screenrc
else
sudo screen -S run_screen -X quit
sudo screen -S run_screen -c new.screenrc
fi
sudo screen -S run_screen -X at rabbitmq stuff "sudo podman run -it --rm --name rabbitmq --network podman --hostname rabbitmq -p 5672:5672 $rabbitmq^M"
sudo screen -S run_screen -X at podman1 stuff "sudo podman run --rm -it --env-file=attributs.env $podman1^M"
sudo screen -S run_screen -X at podman2 stuff "sudo podman run --rm -it --env-file=attributs.env $podman2^M"
sudo screen -S run_screen -X at podman3 stuff "sudo podman run -it --rm --env-file=attributs.env -p 8000:80 $podman3^M"
sudo screen -S run_screen -X at podman4 stuff "sleep 15 && sudo podman run -it --rm --env-file=attributs.env $podman4^M"
sudo screen -r run_screen
new.screenrc
with -d -m
option.Sometimes, you use the commands like this /usr/local/bin/screen -d -m -c /Users/user/my_script/GNUscreen/backup_monitor.screenrc
to start the screen session detached.
As I mentioned before, in this case, the gnu screen won't split windows, even the screen makes the screens. If you reattach the session, there is no split window. you just have to source the your spliting movement in the screen session.
select rabbitmq
split
focus down
select podman1
split -v
focus right
select podman2
split
focus down
select podman3
split
focus down
select podman4
:source new_reload_split.screenrc