Linux – How to start multiple screen sessions automatically

bashgnu-screenlinux

I'm trying to build a command that launches screen, creates four sessions with different names, and run four different commands.

I know how to do this manually:

1. screen
2. ./command1 args
3. CTRL-A :sessionname Session 1
4. CTRL-A C
5. (GOTO 2)

Can I do this with a bash script or something? How would I do so?

Best Answer

screen -dmS "$SESSION_NAME" "$COMMAND" "$ARGUMENTS" will spawn a screen running $COMMAND in the background.

You can see active sessions with screen -ls and reattach with screen -r "$SESSION_NAME".

Dead sessions can be killed with screen -wipe.