#!/bin/bash
#create by szq at 2010-7-28
src_date_format=`date +%F`
dst_date_format=`date +%Y%m%d`
start_time=`date -d "15 minutes ago" +%Y-%m-%d" "%H:%M:%S`
end_time=`date +%Y-%m-%d" "%H:%M:%S`
src_access_content_name="access_content_log."$src_date_format".txt"
dst_access_content_name="access_content_hit_"$dst_date_format".txt"
upload_access_hit_name="content_tophit_"$dst_date_format".txt"
src_userlogin_name="user_login_log."$src_date_format".txt"
dst_userlogin_name="user_login_log."$dst_date_format."txt"
upload_userlogin_name="user_login_"$dst_date_format".txt"
genTopHitContent()
{
cd /u/tomcat5_rh/log/
cp $src_access_content_name upload/$dst_access_content_name
cp $src_userlogin_name upload/$dst_userlogin_name
cd upload
echo "--get log $src_access_content_name from 192.168.32.25:/u/tomcat5_rh/log/$src_access_content_name start.--"
scp root@192.168.32.25:/u/tomcat5_rh/log/$src_access_content_name .
cat $src_access_content_name >>$dst_access_content_name
echo "--get log $src_access_content_name from 192.168.32.25:/u/tomcat5_rh/log/$src_access_content_name end.--"
echo "--get log $$src_userlogin_name from 192.168.32.25:/u/tomcat5_rh/log/$src_access_content_name start.--"
scp root@192.168.32.25:/u/tomcat5_rh/log/$src_userlogin_name .
cat $src_userlogin_name >>$dst_userlogin_name
echo "--get log $$src_userlogin_name from 192.168.32.25:/u/tomcat5_rh/log/$src_access_content_name end.--"
cat $dst_access_content_name | awk 'BEGIN{FS="|";OFS=":"}{hit[$2]++;} END{for(i in hit){print i,hit[i]}}' > tmp
sort -t: -k 2 -g -r tmp | awk 'NR<=10'> $upload_access_hit_name
rm -f tmp
echo $dst_userlogin_name
echo $start_time
echo $end_time
echo $upload_userlogin_name
cat $dst_userlogin_name |awk -F '|' -v starttime="$start_time" -v endtime="$end_time" '{if($2>=starttime&&$2<=endtime)print $1}' > $upload_userlogin_name
ftp -v -n 192.168.201.49<<END
user root tianyi09
binary
hash
cd u/upload
lcd /u/tomcat5_rh/log/upload/
prompt
mput $upload_access_hit_name $upload_userlogin_name
bye
END
}
while true
do
genTopHitContent
sleep 900
done
shell分析日志显示用户点击数
最新推荐文章于 2024-10-07 08:15:00 发布