华域联盟 linux shell shell脚本实现的网站日志分析统计(可以统计9种数据)

shell脚本实现的网站日志分析统计(可以统计9种数据)

写了个shell脚本,可以用来统计每天的访问日志,并发送到电子邮箱,方便每天了解网站情况。
脚本统计了:
1、总访问量
2、总带宽
3、独立访客量
4、访问IP统计
5、访问url统计
6、来源统计
7、404统计
8、搜索引擎访问统计(谷歌,百度)
9、搜索引擎来源统计(谷歌,百度)

复制代码 代码如下:

#!/bin/bash

log_path=/home/www.cnhackhy.com/log/access.log.1

domain="jb51.net"

email="[email protected]"

maketime=`date +%Y-%m-%d" "%H":"%M`

logdate=`date -d "yesterday" +%Y-%m-%d`

total_visit=`wc -l ${log_path} | 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}M\n独立访客:${total_unique}\n\n访问IP统计\n${ip_pv}\n\n访问url统计\n${url_num}\n\n来源页面统计\n${referer}\n\n404统计\n${notfound}\n\n蜘蛛统计\n${spider}\n\n搜索引擎来源统计\n${search}" | mail -s "$domain $logdate log statistics" ${email}

需要修改的三个变量log_path,domain和email,然后把此脚本添加到计划任务,就可以每天接收到统计的数据了。

您可能感兴趣的文章:

本文由 华域联盟 原创撰写:华域联盟 » shell脚本实现的网站日志分析统计(可以统计9种数据)

转载请保留出处和原文链接:https://www.cnhackhy.com/15814.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部