4

I have a script that creates a new screen and executes a command (dev webserver) in it.

screen -S webserver -dm sh launch_webserver.sh

However, when the command is done (or webserver quits), the screen is destroyed. How can I avoid that ?

1
  • Put the commands in your launch_webserver.sh script between a 'while :; do mycommands; done' ?
    – jelle foks
    Commented Jul 10, 2013 at 1:10

1 Answer 1

2

What do you want to happen when the command is finished? The screen session ends when there are no more running commands, so if you want to keep the session around, you'll have to run another command.

If you want to keep the window around and run more commands it it, run a shell when the initial command finishes.

screen -S webserver -dm sh -c 'launch_webserver.sh; echo $?; exec bash -i'

If you want to keep the window around just to see the output, run a command that waits, such as sleep (with a near-infinite argument) or read (waits until you press Enter).

screen -S webserver -dm sh -c 'launch_webserver.sh; echo $?; read'

If you want to keep the session around but not the window, run another command. You'll have to write a screenrc file (which is a good idea anyway).

screen -c /path/to/webserver.screenrc

where /path/to/webserver.screenrc contains

sessionname webserver
screen -t webserver launch_webserver.sh
screen -t shell bash

You must log in to answer this question.