CREATE TABLE `fee_polling` (
`id` int(11) NOT NULL auto_increment COMMENT '自动增长列,主键',
`domainid` int(11) default NULL COMMENT '域的id号',
`OKBS` int(11) default NULL COMMENT '输出带宽',
`IKBS` int(11) default NULL COMMENT '输入带宽',
`BIB` int(11) default NULL COMMENT '入进流量',
`BOB` int(11) default NULL COMMENT '出输流量',
`OBS` int(11) default NULL COMMENT '出输带宽=bob/60',
`IBS` int(11) default NULL COMMENT '输入宽带= bib/60',
`NREQ` int(11) default NULL COMMENT '秒每请求数',
`time` timestamp NULL default NULL COMMENT '采集时间',
`authtime` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `a` (`domainid`,`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='计费模块集采的数据项\r\n带宽,流量,每秒请求数\r\ndomainid对应domain的id\r\n\r\n'
书写的shell脚本:
- [root@ungeoxliu data]# cat my.sh
- #!/bin/sh
- #0 3 * * * /bin/bash /data/scripts/billing/log2user2.sh > /dev/null 2>&1 &
- DIR_BASE="/data/ftp/dcclog/upload/dd/tmp"
- mkdir -p ${DIR_BASE}
- cd ${DIR_BASE}
- mysql -uroot -p123456 -N dcc2 -e "select id,host from dcc_hosts where status=0" > /data/ftp/domain.list
- cat /data/ftp/domain.list|awk '{print $2}' > /data/ftp/puredomain.list
- echo $(date -d "-1 day" "+%Y%m%d") > /data/ftp/datetime.list
- mytime=`cat /data/ftp/datetime.list`
- cat /data/ftp/datetime.list | while read datetime
- do
- find /data/ftp/dcclog/upload/[1-9]*/ -type f -name "squidlog-billing-${datetime}.tgz" | while read file
- do
- dir_base=$(dirname ${file} | awk -F'/' '{print $NF}')
- dir_target="${DIR_BASE}/${dir_base}"
- mkdir -p ${dir_target} && tar zxf ${file} -C ${dir_target}
- done
- done
- for var in `cat /data/ftp/puredomain.list`
- do
- find ${DIR_BASE} -name ${var}-${mytime} > /data/ftp/domainlog.txt
- >/data/ftp/domainalllog.txt
- for log in `cat /data/ftp/domainlog.txt`
- do
- echo "This is a test"
- cat ${log}>> /data/ftp/domainalllog.txt
- done
- firstcolumn=`cat /data/ftp/domainalllog.txt |awk '{print $1}'|head -n 1 `
- cat /data/ftp/domainalllog.txt | awk '{print $2,$3,$4,$5}' >/data/ftp/fourcolumn.txt
- awk '{a[$1]+=$2;b[$1]+=$3;c[$1]+=$4}END{for(i in a)print i,a[i],b[i],c[i]}' /data/ftp/fourcolumn.txt > /data/ftp/fourcolumnmiddle.txt
- sed -i -e "s/^/${firstcolumn} /g" /data/ftp/fourcolumnmiddle.txt
- cat /data/ftp/fourcolumnmiddle.txt | while read line
- do
- echo $line
- echo $line> /data/ftp/singleline.txt
- domainid=`cat /data/ftp/domain.list|grep ${var}| awk '{print $1}' `
- #echo ${domainid}
- okbs=0
- ikbs=0
- bib=`cat /data/ftp/singleline.txt |awk '{print $3}' `
- bob=`cat /data/ftp/singleline.txt |awk '{print $4}' `
- obs=`expr $bob / 60`
- ibs=`expr $bib / 60`
- nreq=`cat /data/ftp/singleline.txt |awk '{print $5}'`
- mytime=`cat /data/ftp/singleline.txt |awk '{print $1" " $2}'`
- authtime="0000-00-00 00:00:00"
- mysql -u root -p'123456' -D dcc2 -e "insert into fee_polling(domainid,okbs,ikbs,bib,bob,obs,ibs,nreq,time,authtime) values('$domainid','$okbs','ikbs','$bib','$bob','$obs','$ibs','$nreq','$mytime','$authtime') "
- done
done
阅读(1250) | 评论(0) | 转发(0) |