shell脚本每天自动统计网站访问日志
2014-04-15 14:59
716 查看
写了个shell脚本,可以用来统计每天的访问日志,并发送到电子邮箱,方便每天了解网站情况。
脚本统计了:
1、总访问量
2、总带宽
3、独立访客量
4、访问IP统计
5、访问url统计
6、来源统计
7、404统计
8、搜索引擎访问统计(谷歌,百度)
9、搜索引擎来源统计(谷歌,百度)
#!/bin/bash
log_path=/home/www.centos.bz/log/access.log.1
domain="centos.bz"
email="log@centos.bz"
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
把此脚本添加到计划任务,就可以每天接收到统计的数据了。
转自:https://www.centos.bz/2012/11/shell-scrpit-auto-count-log/
脚本统计了:
1、总访问量
2、总带宽
3、独立访客量
4、访问IP统计
5、访问url统计
6、来源统计
7、404统计
8、搜索引擎访问统计(谷歌,百度)
9、搜索引擎来源统计(谷歌,百度)
#!/bin/bash
log_path=/home/www.centos.bz/log/access.log.1
domain="centos.bz"
email="log@centos.bz"
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
把此脚本添加到计划任务,就可以每天接收到统计的数据了。
转自:https://www.centos.bz/2012/11/shell-scrpit-auto-count-log/
相关文章推荐
- shell脚本每天自动统计网站访问日志
- 服务自动拉起,定时日志清理,数据统计的shell脚本
- shell脚本实现的网站日志分析统计(可以统计9种数据)
- shell脚本检查统计nginx访问日志access.log
- shell脚本统计nginx访问日志access.log
- 【shell脚本】nginx每天自动切割日志脚本
- 【shell脚本】nginx每天自动切割日志脚本
- 使用shell脚本分析网站日志统计PV、404、500等数据
- 使用shell脚本分析网站日志统计PV、404、500等数据
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- 网站每日PV/IP统计/总带宽/URL统计脚本分享(依据网站访问日志)
- nginx访问日志统计shell脚本
- Shell 命令行统计 apache 网站日志访问IP以及IP归属地
- shel自动统计网站访问日志
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
- 使用Shell脚本自动拒绝某个国家/地区对服务器的访问
- nginx自动切割日志访问文件脚本
- shell中通配符无法使用和/使用dev/null文件自动清除日志脚本