Skip to content

Instantly share code, notes, and snippets.

@calebjones
Last active December 12, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebjones/b9d1c53538c06336b0a6 to your computer and use it in GitHub Desktop.
Save calebjones/b9d1c53538c06336b0a6 to your computer and use it in GitHub Desktop.
#!/bin/sh
# A script to update an RSS feed when player events happen in minecraft server log.
# Integrate with IFTTT or other RSS reader tools to get live alerts.
# For now, just monitors player join/leave events.
# Only keeps last 10 entries in RSS file (rotating out oldest ones).
# Requires: xmlstarlet, perl, uuidgen, and other typical Linux commands.
# Does not manage pid file.
# Cron example (run daily as user specific to this process - not as user who otherwise runs tail)
# Since this isn't run as a proper daemon, just initiate it via
# cron and have it kill/restart this process periodically (daily should be fine).
#00 0 * * * killall tail ; /path/to/minecraft-player-feed.sh
#############################
######### CONFIG ############
# minecraft log file location to monitor
LOG_FILE="/path/to/minecraft/logs/latest.log"
# the RSS file to update (start with empty RSS file with <generator> element)
RSS_FILE="/path/to/public_html/feed.xml"
# URL to prefix <guid>s with (some readers require these to be URLs)
URL="http://your-site.com/feed.xml"
###################################
######### SCRIPT BELOW ############
tail -n 0 -F $LOG_FILE | egrep --line-buffered --colour=NEVER -e "(joined|left) the game" | while read LOGLINE
do
TIME="`perl -e 'use POSIX 'strftime'; print strftime("%a, %d %b %Y %H:%M:%S %z", localtime)'`"
TITLE="`echo \"$LOGLINE\" | cut -d' ' -f 4-`"
GUID="`uuidgen`"
xmlstarlet ed -L -a "//generator" -t elem -n item -v "" \
-s "//item[1]" -t elem -n guid -v "$URL/feed/$GUID" \
-s "//item[1]" -t elem -n title -v "$TITLE" \
-s "//item[1]" -t elem -n link -v "$URL" \
-s "//item[1]" -t elem -n pubDate -v "$TIME" \
-s "//item[1]" -t elem -n description -v "$TITLE" \
-d "//item[position()>10]" $RSS_FILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment