码迷,mamicode.com
首页 > 其他好文 > 详细

feifei_zhang_tongji

时间:2014-07-30 15:02:44      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:mysql

[dodowolf@fu ~]$ cat fu.sh 

#!/bin/sh

LOG_DATE=`date -d "yesterday" +%F`

Q_DATE=`date -d "2 days ago" +%Y%m%d`

Y_DATE=`date -d "yesterday" +%Y%m%d`

while read line

do 

{

 IP=`echo $line | cut -d" " -f1`

 DATABASE=`echo $line | cut -d" " -f2`


 mysql -uuser -ppasswd -h${IP}  -e "set names utf8;select 1,2,3,4,5,6  from  ${DATABASE}.deal_log where inserttime>=‘${LOG_DATE} 00:00:00‘ and inserttime<=‘${LOG_DATE} 23:59:59‘;" | sed ‘1d‘>>/home/fu/fu/${Y_DATE}.txt


}

done</home/fu/fu/ip.txt


wait


 mysql -uuser -ppasswd  -e "create table xx.fu_${Y_DATE} like xx.fu_${Q_DATE};" 

 mysql -uuser -ppasswd --local-infile=1  -e "load data local infile ‘/home/fu/fu/${Y_DATE}.txt‘  into table xx.fu_${Y_DATE};"


[dodowolf@fu ~]$ cat  kou.sh 

#!/bin/sh

LOG_DATE=`date -d "yesterday" +%F`

Q_DATE=`date -d "2 days ago" +%Y%m%d`

Y_DATE=`date -d "yesterday" +%Y%m%d`


mysql -uuser -ppasswd  -e "create table xx.kou_${Y_DATE} like xx.kou_${Q_DATE};" 


while read line

do 

{

 IP=`echo $line | cut -d" " -f1`

 DATABASE=`echo $line | cut -d" " -f2`


 mysql -uuser -ppasswd -h${IP}  -e "set names utf8;select 2,3,4,5,6,7 from  ${DATABASE}.ea_deal  where request_time>=‘${LOG_DATE} 00:00:00‘ and request_time<=‘${LOG_DATE} 23:59:59‘;" | sed ‘1d‘>>/home/fu/kou/ms_${Y_DATE}.txt


}

done</home/fu/kou/ms.txt


wait


while read line

do 

{

 IP=`echo $line | cut -d" " -f1`

 DATABASE=`echo $line | cut -d" " -f2`


 mysql -uuser -ppasswd -h${IP}  -e "set names utf8;select 2,3,4,5,6,7 from  ${DATABASE}.ea_deal  where request_time>=‘${LOG_DATE} 00:00:00‘ and request_time<=‘${LOG_DATE} 23:59:59‘;" | sed ‘1d‘>>/home/fu/kou/yl_${Y_DATE}.txt


}

done</home/fu/kou/yl.txt


wait


sed -i ‘s/$/\tMS/g‘  /home/fu/kou/ms_${Y_DATE}.txt

sed -i ‘s/$/\tYL/g‘  /home/fu/kou/yl_${Y_DATE}.txt


mysql -uuser -ppasswd --local-infile=1  -e "load data local infile ‘/home/fu/kou/ms_${Y_DATE}.txt‘  into table xx.kou_${Y_DATE};"


wait


mysql -uuser -ppasswd --local-infile=1  -e "load data local infile ‘/home/fu/kou/yl_${Y_DATE}.txt‘  into table xx.kou_${Y_DATE};"


本文出自 “石头记” 博客,请务必保留此出处http://dodowolf.blog.51cto.com/793581/1532691

feifei_zhang_tongji,布布扣,bubuko.com

feifei_zhang_tongji

标签:mysql

原文地址:http://dodowolf.blog.51cto.com/793581/1532691

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!