arti
arti

Reputation: 657

How to start multiple screen sessions from bash script

I want after a restart, run two screens with programs in each.

Here is my script:

#!/bin/sh
echo Killing all existing screens...

screen -X -S launcher quit
sleep 2
screen -X -S server quit


echo Loading launcher screen...
screen -S launcher -d -m bash -c  "/home/test/Launcher.exe"
sleep 2
echo Loading server screen...
screen -S server -d -m bash -c  "/home/test/server/server/Server.exe"
echo All done.

Only first one starts and runs fine. I've tried to split them, but still no luck. I have Ubuntu Server 15.10 64bit / Linux 4.2.0-42-generic)

Upvotes: 1

Views: 6502

Answers (2)

Jarek
Jarek

Reputation: 938

You may also explore an option to write .rc scripts for screen. The idea is that all commands you run by multiple invocations of screen, you bundle into a single 'screen script' file and launch with -c, for example:

$ cat screen.rc
startup_message off

screen -t "Pilot" ./pilot_tunel.sh
split
focus
screen -t "AT TB1" ./at_tb1_tunnel.sh
focus

And then start it:

$ screen -c screen.rc

Somehow I found it a bit cleaner.

Also with screen's "split" command we can see output of both scripts in same screen:

enter image description here

I found it useful as well.

I hope it will help, Jarek

PS: Obviously, the example I gave is not mapping your commands. It's just an overview of the functionality.

Upvotes: 3

arti
arti

Reputation: 657

Resolved that problem with launching the app in the screen after initiation first:

screen -dmS launcher
screen -S launcher -X screen  "/home/test/Launcher.exe"
screen -dmS server
screen -S server -X screen "/home/test/server/server/Server.exe"

Upvotes: 1

Related Questions