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 |
I found it, nc, comes from the package netcat. For Debian systems you can get it with "apt-get install netcat"
Handy script. Consider specifying a timeout to nc
e.g. nc -w10 $HOST $PORT
.
Damn, this is ancient 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nc is not distributed by default with some Linux distributions, you might want to specify at least an open source location for it. But most definitely a Debian location for it as Deb systems are the most common.