Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to figure out how to write a script which would start program(s) in GNU Screen sessions(s) at system boot. I am trying this:

screen -S test -d -m -X $HOME/folder/folder/.program \
screen -S test2 -d -m -X $HOME/folder/folder/.program2 \

but the command cant be executed because session is already detached? The only thing that i need is run command in screen session and detach this session immediately.

Thanks for answers, but now i faced another problem. Script stops working after i put some variables for my "program and program2". Something like this:

screen -S test -d -m $HOME/folder/folder/.program -f config.cfg

for some reason "-f config.cfg" got ignored. I am also tried to quote command and doesnt help too.

share|improve this question
Why the -X option? – enzotib Sep 22 '11 at 15:47
up vote 22 down vote accepted

Did you really mean to put the \ at the end of the line? If not then try removing those - they escape the following character.

also, dropping the -X helps the setup work for me, for instance:

screen -S test -d -m -X touch /tmp/test

fails with No screen session found, however:

screen -S test -d -m touch /tmp/test

works fine. As such I suspect the following will work for you:

screen -S test -d -m $HOME/folder/folder/.program
screen -S test2 -d -m $HOME/folder/folder/.program2

Remember, that if you run this at boot time, $HOME is not the same as after you log in as a specific user. If you need to run it as a certain user you'll need to use the likes of su to run it as that user, and specifying the full path will remove any ambiguity:

screen -S test -d -m su - username /home/username/folder/folder/.program
screen -S test2 -d -m su - username /home/username/folder/folder/.program2

Or, you would call the entire script above as su - username /path/to/your/script.

share|improve this answer
Thanks for answers, but now i faced another problem. Script stops working after i put some variables for my "program and program2" – TbMa Sep 23 '11 at 15:30

Like Cry Havok mentioned, you can place the program right on the command-line.

If you really must use the -X option, then a) you need to specify the 'screen' command and b) the session needs to exist beforehand.

screen -dmS test
screen -S test -X screen $HOME/folder/folder/.program
screen -dmS test2
screen -S test2 -X screen $HOME/folder/folder/.program2
share|improve this answer
If you put the program on the command-line, screen exits when the program exits; I don't see a command-line flag to keep the screen open if you want to see the console output. If you start the screen and send the commands separately, as shown here, you may need explicit sleep commands to give screen time to start the session before sending the command. – Chinasaur Dec 15 '14 at 18:09
This answer is very similar to answer which answers a similar question. I prefer this answer more than @CryHavok because this answer executes your program inside your user's default shell (@CryHavok runs your program without a parent shell so when the program dies or you ctrl-c it the screen session is terminated immediately) – Trevor Boyd Smith Apr 13 at 15:01

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.