#!/bin/bash
log_path=/home/www.jb200.com/log/access.log.1
domain="jb200.com"
email="log@jb200.com"
maketime=`date +%Y-%m-%d" "%H":"%M`
logdate=`date -d "yesterday" +%Y-%m-%d`
total_visit=`wc -l ${log_path} |
linuxjishu/13830.html target=_blank class=infotextkey>awk '{print $1}'`
total_bandwidth=`awk -v total=0 '{total+=$10}END{print total/1024/1024}' ${log_path}`
total_unique=`awk '{ip[$1]++}END{print asort(ip)}' ${log_path}`
ip_pv=`awk '{ip[$1]++}END{for (k in ip){print ip[k],k}}' ${log_path} | sort -rn | head -20`
url_num=`awk '{url[$7]++}END{for (k in url){print url[k],k}}' ${log_path} | sort -rn | head -20`
referer=`awk -v domain=$domain '$11 !~ /http://[^/]*'"$domain"'/{url[$11]++}END{for (k in url){print url[k],k}}' ${log_path} | sort -rn | head -20`
notfound=`awk '$9 == 404 {url[$7]++}END{for (k in url){print url[k],k}}' ${log_path} | sort -rn | head -20`
spider=`awk -F'"' '$6 ~ /Baiduspider/ {spider["baiduspider"]++} $6 ~ /Googlebot/ {spider["googlebot"]++}END{for (k in spider){print k,spider[k]}}' ${log_path}`
search=`awk -F'"' '$4 ~ /http://www.baidu.com/ {search["baidu_search"]++} $4 ~ /http://www.google.com/ {search["google_search"]++}END{for (k in search){print k,search[k]}}' ${log_path}`
echo -e "概况n报告生成时间:${maketime}n总访问量:${total_visit}n总带宽:${total_bandwidth}Mn独立访客:${total_unique}nn访问IP统计n${ip_pv}nn访问url统计n${url_num}nn来源页面统计n${referer}nn404统计n${notfound}nn蜘蛛统计n${spider}nn搜索引擎来源统计n${search}" | mail -s "$domain $logdate log statistics" ${email}