Last active
August 29, 2015 14:11
-
-
Save ewized/04f450eb559352c752f3 to your computer and use it in GitHub Desktop.
This script will kill all dead java processes
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 | |
# This script will find kill all dead minecraft servers | |
# It will attempt to restart the servers before they die | |
LAST="" | |
for process in $(ps a | grep java | awk '{print $1 " " $4}') ; do | |
if [ "$LAST" = "" ] ; then | |
LAST=$process | |
else | |
PID=$LAST | |
TIME=${process:0:-3} | |
if (( $TIME > 200 )) ; then | |
kill -9 $PID | |
elif (( $TIME > 100 )) ; then | |
SERVER=$(ps a | grep $PID | awk '{print $10}') | |
SERVER=${SERVER:9} | |
screen -rx $SERVER -X eval 'stuff "stop\015"' | |
fi | |
LAST="" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment