统计push点击次数的shell脚本最初版本1

     在工作中,运营人员需要统计到push被点击的次数,客户端当push被点击打开的时候,服务端会记录到日志文件push_feed_back_log.log中,格式如下:

    2015-04-13 00:05:51,android,queryItemList,81a9831f09baf5f876bf3244db6f2392,pinpait_2862

    2015-04-13 00:06:21,android,queryItemList,1e570c6400ef8e65ad07d5aa865c7779,pinpait_2862

    2015-04-13 00:06:30,android,queryItemList,1e570c6400ef8e65ad07d5aa865c7779,pinpait_2862

    2015-04-13 00:08:20,android,queryItemList,5bbb9bcebf819d2d6f91418982a43414,campaign_568

    2015-04-13 00:09:41,android,queryItemList,9c96753a365ecc8bfb207fdc9c519c6c,campaign_568

    1,如果每次用linux命令去统计,浪费时间,为了提高效率

     于是写了统计的shell脚本:

  

#!/bin/sh

 date=`date   -d   -1day +%Y-%m-%d`;
 masterPath=/home/www/logs/taofen8/master;
 apiPath=/home/www/logs/taofen8/api;
 path=/home/www/logs/taofen8;
 hisPath=/data/history/taofen8;
 log=$path/master/push_feed_back_log.log.$date 
 echo "==============start==================";

if [ ! -f "$log" ]; then
   #判断文件是否存在
   masterPath=$hisPath/master;
   apiPath=$hisPath/api;
fi

 echo "==============date$date===================" > /tmp/mymaster.txt;	

 cat $masterPath/push_feed_back_log.log.$date  |awk -F ","  '{a[$2" "$5]+=1}END{for(i in a) printf "%s %s\n",i,a[i]}' | sort -k 3 -n -r | head -n 15 >>/tmp/mymaster.txt

 echo "===============API==================" >> /tmp/mymaster.txt;	
 
 cat $apiPath/push_feed_back_log.log.$date  |awk -F ","  '{a[$2" "$5]+=1}END{for(i in a) printf "%s %s\n",i,a[i]}' | sort -k 3 -n -r | head -n 15 >>/tmp/mymaster.txt

 echo "=================end================" >> /tmp/mymaster.txt;

   2,服务器授权并执行shell脚本,就会将统计结果输出到/tmp/mymaster.txt文件中:

   格式如下:

   ==============date2015-04-12===================

android pinpait_2862 93

android campaign_568 66

android pinpait_2930 25

iphone campaign_568 23

===============API==================

android campaign_568 702

android pinpait_2862 239

android pinpait_2930 158

iphone campaign_568 116

iphone pinpait_2862 77

=================end================

相关推荐