【问题标题】:How to get access_log summary by goaccess starting from certain date?如何从某个日期开始通过 goaccess 获取 access_log 摘要?
【发布时间】: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


    【解决方案1】:

    您可以将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
    • @ohho Duh,我试图提醒自己,但还是忘记了!感谢您的说明 -- 已更新。
    • 从手册页中,这也应该可以工作:zcat -f access.log* | sed -n '/'`date +"01\/%b\/%Y"`'/,$ p' | goaccess --output-format=csv
    • 顺便说一句,[0-3][1-9] 应该是[0-3][0-9]吗?
    猜你喜欢
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    相关资源
    最近更新 更多