#!/bin/bash
#===============================================================================
#
#          FILE: webtool_log2db_m11
#
#         USAGE: webtool_log2db_m11
#
#   DESCRIPTION: Convert from log(-10 minutes) file to WebTool log_search
#
#       OPTIONS: 
#
#          BUGS:  ---
#        AUTHOR: rickz (Rick Zhang), xlrickz@gmail.com
#       COMPANY: X-LEGEND Entertainment Corp.
#       CREATED: Mon Nov 28 02:01:08 EST 2011
#      REVISION: 1.0
#
#          TODO:
#
#===============================================================================
#set -o nounset                              # Treat unset variables as an error
#set -m                                      # Enable job control

source ~/.gamerc

PREV_TEN_MINUTES_DATE="$(date -d "-10 minutes" +"%Y/%m/%d %H:%M"|head -c 15)"

for MissionServerDir in ~/server*/MissionServer*;do

        # Kingdom War Log ( MissionServer )
        [ -d $MissionServerDir ] && cd $MissionServerDir || continue
        export SET=$(get_set $(awk -F/ '{print $NF}' <<< $MissionServerDir))

        grep -h "^[ 0-9]\+,$PREV_TEN_MINUTES_DATE" $(
                ls -tr KingdomWar*log* 2> /dev/null|tail -2
        )|\
	LC_ALL=C nice -19 egrep 'player join'|\
	sed "s/'/''/g" |\
	nice -19 ~/bin/log2any.py mskingdomwar $SET 2>> ~/log2db_debug.log

done
