source ~/.gamerc

#WorkDIR=~/www/core
corefile=ak_core_list
date=`date +%Y-%m-%d' %T'`

COREDUMP_ROOT_DIRECTORY="${WORKING_DIRECTORY}/www/core"
COREDUMP_OLD_DIRECTORY="${WORKING_DIRECTORY}/www/core/live_core_dump"
#TIME_INTERVAL="5"
#CHECK_TIME_INTERVAL=$(date --date="${TIME_INTERVAL} minutes ago" +'%Y-%m-%d %H:%M') 
TEST_SERVER_IP=${TEST_SERVER_GLOBAL_IP}
PATCH_SERVER_IP=${REMOTE_PATCH_SERVER}
REMOTE_DIRECTORY_ON_PATCH="upload/${COUNTRY_CODE}"


cd ${COREDUMP_ROOT_DIRECTORY}


if ls ${COREDUMP_ROOT_DIRECTORY}/*.gz   ; then

check1="$(ls -trl ${COREDUMP_ROOT_DIRECTORY} |grep gz |tail -n 1 |md5sum)"
check2="$(sleep 10;ls -trl ${COREDUMP_ROOT_DIRECTORY} |grep gz |tail -n 1 |md5sum)"
file=`ls -trl ${COREDUMP_ROOT_DIRECTORY} |grep gz |tail -n1 |awk  '{print$9}'`


        if [ "$check1" == "$check2" ] ; then
                #echo upload core dump
                lftp -e "mput ${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz ; quit" http://${PATCH_SERVER_IP}/${REMOTE_DIRECTORY_ON_PATCH}
                echo $date $file >> ${COREDUMP_ROOT_DIRECTORY}/$corefile
		ls ${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz -hltra | awk -F" " '{print $9}' | sed "s/^/\/upload\/${COUNTRY_CODE}\//"
                mv ${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz ${COREDUMP_OLD_DIRECTORY}
        fi
fi

