Last active
June 1, 2017 12:01
-
-
Save SamEureka/4f43d6fb6186fbb93cbcd86d6b2126d7 to your computer and use it in GitHub Desktop.
Stop some servers running in "Screen"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment