Last active
June 17, 2023 22:14
-
-
Save MOZGIII/4529750 to your computer and use it in GitHub Desktop.
Minecraft Server Pinger for server hang detection written on Bash
This file contains hidden or 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 | |
# Minecraft Server Pinger | |
# | |
# If the server is pining successfully exits with 1, | |
# else (if server hangs) exits with 0. | |
HOST=$1 | |
PORT=$2 | |
if [[ "x$HOST" == "x" || "x$PORT" == "x" ]]; then | |
echo "Usage: $0 host port" | |
exit 1 | |
fi | |
VAL=$(( echo -n -e "\xFE\x01"; sleep .5) | nc $HOST $PORT | wc -m) | |
if [[ $VAL -gt 2 ]]; then | |
echo Server is ok! | |
exit 1 | |
else | |
echo FAIL | |
exit 0 # allow chained script to work, use it like this: pinger && /etc/init.d/mc restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Damn, this is ancient 😄