Create screen and run command without attaching

Solution 1:

I think you may be running into several issues.

If the command finishes before you re-attach, the screen will go away. You can demo this by using:

screen -d -m ls -l

It will run the ls -l command, but screen -list won't show it as the screen process has ended.

I also have no idea what you are trying to do with this \015 stuff. Perhaps updating your question would help, as what I think you're trying to do is run multiple commands in a screen session. This should be as simple as:

screen -d -m bash -c "command1 ; command2 ; command3"

If these are used a lot, perhaps you should make a shell script that runs just these commands, then use a more simple:

screen -d -m /path/to/script.sh

Solution 2:

Start a detached screen

screen -dmS <screen name>

Execute command in previously created detached screen

screen -S <screen name> -X stuff '<CMD>\n'

Yes you need to type the enter symbol to submit the command or else it will just add the string to the screen.

http://osdir.com/ml/gnu.screen/2003-09/msg00029.html