From 6cc3770cd1178b1ad0f4d8d16999350dc999f343 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 7 Dec 2011 18:37:28 -0800 Subject: [PATCH] script to trace history of one game in db by polling db and listing changes --- xwords4/relay/scripts/track_room.sh | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 xwords4/relay/scripts/track_room.sh diff --git a/xwords4/relay/scripts/track_room.sh b/xwords4/relay/scripts/track_room.sh new file mode 100755 index 000000000..3f4ade0e3 --- /dev/null +++ b/xwords4/relay/scripts/track_room.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +set -e -u + +CONNNAME="" +LASTLINE="" +INTERVAL=30 + +usage() { + [ $# -gt 0 ] && echo "Error: $1" + echo "Usage: $(basename $0) connname" + exit 1 +} + +read_row() { + echo "select * from games where connname='${CONNNAME}';" | psql xwgames | grep $CONNNAME +} + +print_line() { + echo "$(date): $LASTLINE" +} + +[ $# -eq 1 ] || usage + +CONNNAME=$1 +LASTLINE=$(read_row $CONNNAME) +[ -z "$LASTLINE" ] && usage "$CONNNAME not found" + +print_line + +while :; do + sleep $INTERVAL + NEWLINE=$(read_row) + if [ "$NEWLINE" != "$LASTLINE" ]; then + LASTLINE="$NEWLINE" + print_line + fi +done