首页 > 代码库 > feifei_zhang_tongji
feifei_zhang_tongji
[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