Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to edit my rc.local file to start up a few server sessions each in it's own GNU screen. However, whenever I stop a server, the screen terminates.

Currently I have:

screen -dmS test ~/tmp/runserver.sh

with this inside runserver.sh:

node ~/dev/mouser/app.js

How do I get the screen to stay alive after the passed in command or script terminates?

share|improve this question

1 Answer 1

Two ways. Either invoke a shell to run the script, which then replaces itself (using the exec builtin) with an interactive shell when the script is done

screen -dmS test bash -c '~/tmp/runserver.sh; exec bash'

or keep your current screen command and put exec bash in your runserver.sh script.

node ~/dev/mouser/app.js
exec bash

(On a side note, there's no point in having an extension on a script. It will just give you dependency headaches later if you rewrite it in another language. If you look in /bin and /usr/bin, you'll find a lot of sh, bash and python scripts; none of which have a .sh, .bash or .py extension)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.