I want to script the creation of a gnu-screen session in order to start it quickly on an Ubuntu server because I'm lazy when it comes to opening screen panes.
Let's work with this rather simple screen session, which must have those 3 panes:
+--------------------------+
| htop |
+--------------------------+
| watch ps | watch cpu |
+--------------------------+
Here is my current bash script:
#!/bin/bash
reset
SESSION="monitoring"
NL=$'\n'
if screen -list | grep -q "\.${SESSION}"; then
echo "Screen session '${SESSION}' already exists."
echo "Attach with: screen -r ${SESSION}"
exit 1
fi
screen -dmSU "${SESSION}"
sleep 0.2
screen -S "${SESSION}" -X split
screen -S "${SESSION}" -X focus
screen -S "${SESSION}" -X split -v
screen -S "${SESSION}" -X focus
screen -S "${SESSION}" -X stuff "watch -n4 'sensors | grep CPU'${NL}"
screen -S "${SESSION}" -X focus
screen -S "${SESSION}" -X stuff "watch -n 1 'ps aux --sort=-%cpu | head -20'${NL}"
screen -S "${SESSION}" -X focus
screen -S "${SESSION}" -X stuff "htop${NL}"
screen -S "${SESSION}" -X equal
screen -S "${SESSION}" -X layout save default
screen -r "${SESSION}"
but it only attach to the last screen pane and the other are "lost" (I cannot see them using Ctrl-a " or Ctrl-a w)
How can I achieve that with my script?