【发布时间】:2014-12-24 20:20:59
【问题描述】:
目前我保留了 6 周的 apache access_log。如果我在月底生成访问摘要:
cat /var/log/httpd/access_log* | goaccess --output-format=csv
摘要将包括上个月的一些访问数据。
如何跳过上个月的日志并从当月的第一天开始总结?
附言数据格式为:%d/%b/%Y
【问题讨论】:
标签: bash apache centos goaccess
目前我保留了 6 周的 apache access_log。如果我在月底生成访问摘要:
cat /var/log/httpd/access_log* | goaccess --output-format=csv
摘要将包括上个月的一些访问数据。
如何跳过上个月的日志并从当月的第一天开始总结?
附言数据格式为:%d/%b/%Y
【问题讨论】:
标签: bash apache centos goaccess
您可以将cat 的无用用途换成有用的grep。
grep -n $(date +'[0-3][0-9]/%b/%Y') /var/log/httpd/access_log* |
goaccess --output-format=csv
如果日志是按日期记录的,那么跳过您知道太旧或太新的日志会更经济,即修改通配符参数,以便只匹配您真正想要的文件(或运行类似find -mtime -30 至少将集合缩小到几个文件)。
(cat 是没用的,因为如果goaccess 完全正确编写,它应该能够处理
goaccess --output-format=csv /var/log/httpd/access_log*
很好。)
【讨论】:
grep --no-filename $(date +"[0-3][1-9]/%b/%Y")(goaccess 需要--no-filename)
zcat -f access.log* | sed -n '/'`date +"01\/%b\/%Y"`'/,$ p' | goaccess --output-format=csv
[0-3][1-9] 应该是[0-3][0-9]吗?