Skip to content

Instantly share code, notes, and snippets.

@travis-g
Last active May 21, 2016 03:00
Show Gist options
  • Save travis-g/1f5819b1d9eb8b0af88bfa91245d5310 to your computer and use it in GitHub Desktop.
Save travis-g/1f5819b1d9eb8b0af88bfa91245d5310 to your computer and use it in GitHub Desktop.
Online player info of Minecraft servers
#!/bin/sh
help () {
cat <<EOF
usage: $(basename $0) [-hcl]
-h print this help
-c print player count (default)
-l list player names
environment:
PORT the server port, default 25565
SERVER the server script/daemon, default ~/minecraft
EOF
}
test "$1" = "-h" && help && exit 0
# env
PORT=${PORT:-25565}
SERVER=${SERVER:-~/minecraft}
NUM=`netstat -anp 2>/dev/null | grep :$PORT | grep ESTABLISHED | wc -l`
list () {
$SERVER command '/list' | tail -n $NUM | rev | cut -d" " -f1 | rev
}
case $1 in
-h) help ;;
-l) list ;;
*) echo $NUM ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment