Minecraft – How to a script check if the local server is running

minecraft-java-editionminecraft-java-edition-server

Before version 1.7.2 I was able to check if the server was running by using a shellscript that checked if server.log.lck was in the Minecraft server directory. I am running multiple servers via screens, so I want to be sure that the server is not running before I start it.
Because 1.7.2 introduced a new logging system, this is not possible anymore.

I use a shell script where I have an unique port and an unique screen name for each server.

How can I now determine if the server is running?

Best Answer

I sorted it out by using the following if in my shell script:

if ! screen -list | grep -q $SCREEN_NAME; then
    ONLINE=1
else
    ONLINE=0
fi

Where $SCREEN_NAME is the server's unique screen name.