#!/bin/bash

source ~/.gamerc

FILE_NAME='/tmp/server_core.src'
OUTPUT_FILE_NAME='/tmp/old_server_core_dump.sql'

COREDUMP_ROOT_DIRECTORY="${WORKING_DIRECTORY}/www/core"
COREDUMP_OLD_DIRECTORY="${WORKING_DIRECTORY}/www/core/live_core_dump"
TEST_SERVER_IP=${TEST_SERVER_GLOBAL_IP}
PATCH_SERVER_IP=${REMOTE_PATCH_SERVER}
REMOTE_DIRECTORY_ON_PATCH="upload/${COUNTRY_CODE}"
TODAY=$(date +'%Y%m%d')

if [ -f ${OUTPUT_FILE_NAME} ] ; then
	rm -rf ${OUTPUT_FILE_NAME}
fi

for coredump in $(cat ${FILE_NAME}); do
	echo ${coredump}
	SERVER_NAME=$(echo ${coredump} | awk -F"." '{print $1}' | cut -d "-" -f3)
	YEAR=$(echo ${coredump} | awk -F"." '{print $3}' | cut -c1-4)
	MONTH=$(echo ${coredump} | awk -F"." '{print $3}' | cut -c5-6)
	DAY=$(echo ${coredump} | awk -F"." '{print $3}' | cut -c7-8)
	HOUR=$(echo ${coredump} | awk -F"." '{print $3}' | cut -c10-11)
	MINUTE=$(echo ${coredump} | awk -F"." '{print $3}' | cut -c12-13)
	SECOND=$(echo ${coredump} | awk -F"." '{print $3}' | cut -c14-15)

	echo "INSERT INTO crashlog_precisely (server_name, regdate, core_dump_site) values ('${SERVER_NAME}', '${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}:${SECOND}', '<A HREF=\"http://${TEST_SERVER_IP}/core/live_core_dump/${TODAY}/${coredump}\">/upload/${COUNTRY_CODE}/${coredump}</a>');" >> ${OUTPUT_FILE_NAME}
done
