Skip to content

Instantly share code, notes, and snippets.

@SamEureka
Created October 24, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamEureka/9913efae6584abed827eca4d72c7d196 to your computer and use it in GitHub Desktop.
Save SamEureka/9913efae6584abed827eca4d72c7d196 to your computer and use it in GitHub Desktop.
check script
#!/bin/bash
# Create an array with the screen instance names. (The screen names are 10 characters because I suck at REGEX)
LIST=(`screen -list |grep -o '[a-z]\{10\}'`)
# Iterate over the array to do the work.
for i in "${LIST[@]}"; do
# Create a working string variable with the name
work="$i"
check=`screen -list |grep $work`
#check to see if the server is running
if [[ -z $check ]]
then
echo "${work} is not running"
else
echo "${work} is running, we are going to try an shut it down."
screen -S ${work} -p 0 -X stuff "stop$(printf \\r)" &&
# sleep 15
while [[ -z $truth ]]; do
let truth=`screen -list |grep $work`
if [[ -z truth ]]
then
echo "stopped!"
else
echo -r "#"
echo -r "$"
fi
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment