教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 shell awk读取Nginx 5分钟内的访问日志数

shell awk读取Nginx 5分钟内的访问日志数

发布时间:2014-12-02   编辑:jiaochengji.com
本文分享一例简单的shell脚本,用于读取Nginx最近5分钟的访问日志数,有需要的朋友参考下。

一个读取Nginx最近5分钟内的访问日志数的shell脚本。

例子:
 

复制代码 代码示例:
#!/bin/bash
#edit: www.jiaochengji.com
#
date1=`date -d "$date1" +%Y%H%M` 
logpath="access.log" 
cat $logpath |awk -v now=$date1 'BEGIN{count=0}{if(match($4,'/\\\\/[0-9:]+/')){ date=substr($4,RSTART+1,10);if(date>=now && match($10,"500")){count=count+1;}}} END{print count}'

您可能感兴趣的文章:
shell awk读取Nginx 5分钟内的访问日志数
检测apache与nginx的80端口并自动重启的脚本
shell统计pv与uv、独立ip的方法
如何用shell脚本分析网站日志统计PV、404、500等数据
分析日志统计网站pv 404 500状态码的shell脚本
自动统计网站访问日志的shell脚本
shell脚本实现网站日志分析统计
查看IP访问量的shell脚本汇总
awk抽出指定时间段内的日志
MySQL主从服务器配置的一些总结

[关闭]
~ ~