Niklas
Niklas

Reputation: 505

How to check in If-Statement if a screen is already running

I want to write a bash script where I check If my Screen (I gave this screen the name a3_altis) is already running or not, just like this:

if (screen a3_altis is running)
  then
    ./stop.sh
    sleep 5
    ./start.sh
  else
    ./start.sh
fi

I'm new in Bash, so I don't really know how to check If a screen is running.

Upvotes: 0

Views: 454

Answers (1)

William Pursell
William Pursell

Reputation: 212404

screen may provide a more robust mechanism, but it should suffice to just use grep:

if screen -ls | grep -q a3_altis; then
    ./stop.sh
    sleep 5
fi
./start.sh

Upvotes: 1

Related Questions