Shell 脚本:在访问日志中查找指定日期时间段内响应 500 的条目

Qui*_*Par 4 shell-scripting

有人可以帮助我使用 shell 脚本来计算指定时间范围内访问日志中 500 个 HTTP 响应条目的数量吗?

qua*_*nta 5

您可以使用awk在指定的时间范围内过滤:

# awk '$9 == "500" && $4 <= to && $4 >= from { print $0 }' from="[02/Aug/2011:14:30:00 +0700]" to="[02/Aug/2011:14:32:00 +0700]" /path/to/your/access_log | wc -l
Run Code Online (Sandbox Code Playgroud)

状态代码和时间戳字段可能有不同的顺序。也改变fromto对应你所使用的格式。