导入日志文件到mysql数据库表

#!/bin/bash
#****************************************************************************
#***将/usr/local/data/目录下每天的日志,导入数据库
#***导入某一天数据: ./load2mysql.sh 20140101
#***导入某一段时间数据: ./load2mysql.sh 20140101 20140110
#***不传参数默认导入昨天的数据: ./load2mysql.sh
#****************************************************************************
#export path=$path:/d/MySQL5.5/bin
#log_path=load2mysql.log
#echo `date +"%Y-%m-%d %T"` >>${log_path}
#echo "...开始执行" >>${log_path}
mysql_bin=/d/mysql5.5/bin

#args_num=$#
#if [ $args_num -eq 0 ];then
# date1=`date -d "-1 day" +"%Y%m%d"`
# date2=`date -d "-1 day" +"%Y%m%d"`
#elif [ $args_num -eq 1 ];then
# date1=$1
# date2=$1
#elif [ $args_num -eq 2 ];then
# date1=$1
# date2=$2
#else
# echo "...参数错误,退出" >>${log_path}
# exit
#fi

#echo "...参数:[${date1}][${date2}]" >>${log_path}

#beg_s=`date -d "$date1" +%s`
#end_s=`date -d "$date2" +%s`
pth=`pwd`
#while [ "$beg_s" -le "$end_s" ];do
#datestr=`date -d @$beg_s +"%Y%m%d"`;
for dir in $(ls .)
do
#[ -d $dir ] && echo $dir
if [ $dir == 'load2mysql.sh' ];then
continue
fi

for f in $(ls $dir)
do
pth2=$pth/$dir/$f
for logfile in `ls ${pth2}`
do
lgfile=${pth2}/${logfile}
#load_sql="load data infile ${lgfile} into table ${dir} fields terminated by '#@@#'"
#{mysql_bin}/mysql -u root -p'123456' sanguo_log -e "${load_sql}"
dest_logfile=${pth}/${dir}/${f}/${dir}.txt
echo ${dest_logfile}
cp ${lgfile} ${dest_logfile}
${mysql_bin}/mysqlimport -uroot -p'123456' --fields-terminated-by='#@@#' --lines-terminated-by='\r\n' sanguo_log ${dest_logfile}
rm -f ${dest_logfile}
mv ${lgfile} ../game_log_imported/
done
done
done

#mysqldump -u root -p'**********' my_db tbl_logs >tbl_logs.sql

上一篇:IIS7配置PHP运行环境


下一篇:排序算法总结(二)归并排序【Merge Sort】