Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can screen be used to start a new session and run a command within that session without killing that session?

 screen -S myScreenName runSomething

I tried the above command and it says

[screen is terminating]

Did it run the command then kill the screen? I would like the screen to be detached after running the command instead of killing it. How can that be done?

share|improve this question
1  
Why are you using screen here at all, if the command is just going to exit immediately? –  Michael Hampton Feb 27 at 2:29
    
@MichaelHampton the command doesn't exit immediately, it runs a daemon that prints to stdout, so I would like to keep it in a screen session. I will be starting the screen session from an Ansible playbook. I don't know why screen terminates when I ran that command. –  Nyxynyx Feb 27 at 2:32
    
Then tell the daemon not to daemonize. –  Michael Hampton Feb 27 at 2:35
    
@MichaelHampton Great that works. Can screen be asked to detach after running the command? Tried -d but it says There is no screen to be detached matching myScreenName –  Nyxynyx Feb 27 at 2:50

1 Answer 1

to run a command and detach from the session:

screen -d -m runSomething
share|improve this answer

Your Answer

 
discard

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.