Run commands in separate new screen sessions/tabs

Send commands to tabs in screen.

screen_name="my_screen"
 
# Start screen in "detached" mode with a session name.
screen -S "${screen_name}" -t "master" -d -m
 
# Wait for screen to be ready before opening new sessions.
sleep 1
 
# Create and send commands to tabs.
screen -S "${screen_name}" -X "screen" -t "my_screen_1"
screen -S "${screen_name}" -p "my_screen_1" -X stuff $'bash script_1.sh\n'
 
screen -S "${screen_name}" -X "screen" -t "my_screen_2"
screen -S "${screen_name}" -p "my_screen_2" -X stuff $'bash script_2.sh\n'
 
screen -S "${screen_name}" -X "screen" -t "my_screen_3"
screen -S "${screen_name}" -p "my_screen_3" -X stuff $'bash script_3.sh\n'

Quick screen reference

Create new windowControl-a + c
Next windowControl-a + n
Previous windowControl-a + p
DetachControl-a + d

List screen sessions

$ screen -ls

Attach to screen

$ screen -x
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment