shell分析日志导入数据库

1:mycomm.sh -> 数据库连接

#!/bin/sh
test_db=test
optest="mysql -hlocalhost -uroot -ptyu!@!*T2 --default-character-set=utf8 -N "
now_time=`date +%s`

 

2.mystat.sh ->读取日志awk分析后导入数据库

#!/bin/sh
source /usr/local/stat/shell/mycomm.sh
stime=`date +%F‘ ‘%H:%M -d "1 minute ago"`
etime=`date +%F‘ ‘%H:%M`

tmp_list="$0.list"

filename(){
if [ "`date +%M`" == "00" ]
then
day=`date +%F‘-‘%H -d ‘-1 hour‘`
if test -e $log_path/chess_sys.log-$day
then
chess_log="$log_path/chess_sys.log-$day"
else
chess_log="$log_path/chess_sys.log"
fi
else
chess_log="$log_path/chess_sys.log"
fi
}


player_coupon_log(){
$optest stat -e "truncate table player_coupon2_tmp"
$optest stat -e "truncate table player_coupon3_tmp"
log_path="/usr/local/stat/log"
filename
#1.领取
cat $chess_log|awk -v vtime="$stime" -v wtime="$etime" -F ‘|‘ ‘{if(($1>=vtime)&&($1<wtime)) print $0}‘|grep ‘|ADD_ITEM‘|awk -F ‘|‘ ‘OFS="|"{print $1,$6,$7,$10,1}‘ > $tmp_list
$optest stat -e "load data local infile ‘$tmp_list‘ into table player_coupon fields terminated by ‘|‘ (create_time,player_id,item_id,coupon_id,status)"
cat $tmp_list

#2.兑换
cat $chess_log|awk -v vtime="$stime" -v wtime="$etime" -F ‘|‘ ‘{if(($1>=vtime)&&($1<wtime)) print $0}‘|grep ‘|USE_ITEM‘|awk -F ‘|‘ ‘OFS="|"{print $1,$7}‘ > $tmp_list
$optest stat -e "load data local infile ‘$tmp_list‘ into table player_coupon2_tmp fields terminated by ‘|‘ (update_time,item_id)"
$optest stat -e "update player_coupon a, player_coupon2_tmp b set a.status=2, a.update_time=b.update_time where a.item_id=b.item_id"
cat $tmp_list

#3.过期
cat $chess_log|awk -v vtime="$stime" -v wtime="$etime" -F ‘|‘ ‘{if(($1>=vtime)&&($1<wtime)) print $0}‘|grep ‘|GED_ITEM‘|awk -F ‘|‘ ‘OFS="|"{print $1,$7}‘ > $tmp_list
$optest stat -e "load data local infile ‘$tmp_list‘ into table player_coupon3_tmp fields terminated by ‘|‘ (update_time,item_id)"
$optest stat -e "update player_coupon a, player_coupon3_tmp b set a.status=3, a.update_time=b.update_time where a.item_id=b.item_id"
cat $tmp_list
}

player_coupon_log
date

 

shell分析日志导入数据库

上一篇:CentOS PostgreSQL 12 流复制(主从切换)


下一篇:Oracle学习笔记:序列sequence的创建与应用