I want to execute a command in a new screen session (and detach from it) but I don't get it to work. I tried to start a process in a new screen session and detach from it with this:

screen -d -m mycommmand

But when I try to attach to that screen session with

screen -r

I get the message "There is no screen to be resumed". I also tried to start a command in a new screen session with

screen mycommand

When I do that, a new screen session starts but the command doesn't get executed.

The command is a .sh script that starts a game server but the game server doesn't start.

[Edit] Because some people asked for the exact command, here it is: It's a bash script that should start a minecraft server in a seperate screen session.


Here is the .sh script:

cd "/home/tim/minecraft/survivalServer"
screen -S "minecraft-server-1-14-4" -m -d /home/tim/java/bin/java -Xmx4096M -Xms1024M -jar /home/tim/minecraft/survivalServer/minecraft_server.1.14.4.jar nogui

Now, the problem is, that when I run the script it fails to create the new screen session. Why is that?

Help is much appreciated. Thanks

  • Try it without the -d and see what happens. I'm guessing that something is causing mycommand to exit prematurely.
    – TexasDex
    Jul 25, 2019 at 21:17
  • leaving out the -d changes nothing. The command doesn't get executed.
    – Tim Kluge
    Jul 26, 2019 at 13:48
  • Does the command without screen (i.e. /home/tim/java/bin/java -Xmx4096M -Xms1024M -jar /home/tim/minecraft/survivalServer/minecraft_server.1.14.4.jar nogui) start the server as expected? Jul 29, 2019 at 5:49
  • No, it only starts the server without the screen command. Like I said I dont know why but the screen command doesnt seem to do what it should do...
    – Tim Kluge
    Jul 29, 2019 at 9:09

1 Answer 1


The problem is that you are trying to launch a nested, detached screen instance inside a detached screen instance. Your script contains the line:

screen -S "minecraft-server-1-14-4" -m -d /home/tim/java/bin/java -Xmx4096M -Xms1024M -jar /home/tim/minecraft/survivalServer/minecraft_server.1.14.4.jar nogui

This launches screen, names the screen session minecraft-server-1-14-4 then launches minecraft and detaches. But you are also attempting to run screen -d -m ./startserver.sh. So, before the screen session is created in the script you are already running the script inside a detached screen session. This... doesn't tend to work so well.

It's functionally the same as this:

wolferz@khaos ~ $ screen -m -d screen -S 'mysession' -m -d top
wolferz@khaos ~ $ screen -r
There is a screen on:
        24850.mysession (07/24/2019 10:47:46 PM)        (Dead ???)
Remove dead screens with 'screen -wipe'.
There is no screen to be resumed.

What you want to do is run the script directly. Just do ./startserver.sh. That should drop you back at the prompt. You can then attach to your minecraft console by doing screen -r as normal.

  • I was going to say this and more, but I won't duplicate your answer. The "more" part is: in my tests screen -m -d top is different than screen -d -m top; the latter seems right but the OP has -m -d in the script. I wonder if it adds to the problem. Jul 26, 2019 at 22:46
  • I attempted this with -d -m as well. Similar result (no dead session... but also no detached session). The screen manpage specifically shows -d -m and -D -m. But there is definitely a difference between the two orders. I suspect that the -m flag gets ignored if -d is first. Jul 26, 2019 at 22:51
  • Yes, with nested screens I get no difference, it doesn't work either way. I meant non-nested. Let's wait for the OP, maybe your solution is enough. My point: if it's not, the OP should try -d -m in the script. Jul 26, 2019 at 22:55
  • Hmm, good point. Jul 26, 2019 at 22:56
  • The thing is, I'm trying to start the script directly but it doesnt create the new screen session...
    – Tim Kluge
    Jul 27, 2019 at 7:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .