Minecraft Server Status from command line

From The IT Community
Jump to: navigation, search




This can be useful for minecraft sysadmins who love the command-line, or for including into your performance-monitoring system. As a sysadmin, you should already have a performance-graphing thingamabob you could integrate this into.

(echo -ne '\xfe\x01'; sleep 1) | telnet mcserver.yourdomain.net 25565 2>/dev/null |awk -F'\x00\x00' '$2 {print $5}'

For something more human friendly, I put this into /usr/local/bin/mcstatus.

#!/bin/bash
if [ ! "$1" ]; then
  echo "usage: $(basename $0) hostname [portnum]"
  echo "  reports status of that minecraft server"
  exit 1
fi
host="$1"
[ "$2" ] && port=$2 || port=25565

(echo -ne '\xfe\x01'; sleep 1) | telnet $host $port 2>/dev/null \
| awk -F'\x00\x00' '$2 {print "players: "$5"/"$6"\nmotd: "$4"\nversion: "$3;}'

TODO: awk will exit successfully with no input and it is the last part of the pipe; should fix this so it will error out properly if the telnet fails



Was this article helpful? Then please donate to keep The IT Community alive...

If you found this article helpful please share it, comment and help others by writing your own article.






Translate this page:




Articles found in the same category:
(max. 20 shown)