Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  shell  >  正文 shell脚本实现网站日志分析统计

shell脚本实现网站日志分析统计

发布时间:2014-12-24   编辑:www.jquerycn.cn
本文介绍了shell脚本实现的网站日志分析统计,可以统计9种数据,如访问量、带宽、访客量、IP统计、搜索引擎等,非常实用的一段shell脚本,有需要的朋友参考下。

如何用shell脚本分析与统计每天的访问日志,并发送到电子邮箱,以方便每天了解网站情况。
今天脚本小编为大家介绍一款不错的shell脚本,可以实现如上功能。

本脚本统计了:
1、总访问量
2、总带宽
3、独立访客量
4、访问IP统计
5、访问url统计
6、来源统计
7、404统计
8、搜索引擎访问统计(谷歌,百度)
9、搜索引擎来源统计(谷歌,百度)

完整代码:
 

复制代码 代码示例:
#!/bin/bash
log_path=/home/www.jquerycn.cn/log/access.log.1
domain="jquerycn.cn"
email="log@jquerycn.cn"
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脚本实现网站日志分析统计
分析apache日志中蜘蛛爬行记录数量的shell脚本(图文)
如何用shell脚本分析网站日志统计PV、404、500等数据
自动统计网站访问日志的shell脚本
分析日志统计网站pv 404 500状态码的shell脚本
搜索引擎蜘蛛爬行统计分析
shell脚本:MySQL慢查询日志和错误日志按天轮询
google排名因素列举
一个监控网站运行情况的shell脚本
Linux系统下nginx php实现清理服务器网站日志

关键词: linux shell  shell  日志分析   
[关闭]