Skip to content

Instantly share code, notes, and snippets.

@ewized
Last active August 29, 2015 14:11
Show Gist options
  • Save ewized/04f450eb559352c752f3 to your computer and use it in GitHub Desktop.
Save ewized/04f450eb559352c752f3 to your computer and use it in GitHub Desktop.
This script will kill all dead java processes
#!/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