【问题标题】:shellscript to monitor nginx log file on Gentoo expires after log file was gzip'ed用于监控 Gentoo 上的 nginx 日志文件的 shell 脚本在日志文件被 gzip 压缩后过期
【发布时间】:2010-12-10 04:38:28
【问题描述】:

这是我previous question的后续问题

所以我有这个 shellscript 来监控 Gentoo 上的 nginx 日志文件,问题是日志文件在特定文件大小或一段时间后被重命名和 gzip,shellscript 仍在查找原始文件描述符(或 inode? ),新的文件内容不会显示出来。

我的问题是,如何连接到 auto-gzip 脚本以让我的日志文件监控脚本重新启动以监控 日志文件?

顺便说一句,请不要使用 cronjob 或使用计时器来执行此操作。我想要对我的监控脚本进行近乎实时的响应。

【问题讨论】:

    标签: linux shell nginx logfiles gentoo


    【解决方案1】:

    tail 使用-F 标志而不是-f 标志(或--follow=name 也可以,尽管这仅适用于Linux,而-F 也适用于BSD 和Mac OS X ):

       --retry
              keep trying to open a file even if it is inaccessible when  tail
              starts  or  if it becomes inaccessible later -- useful only with
              -f
    
       -f, --follow[={name|descriptor}]
              output appended data as the file grows; -f, --follow, and --fol-
              low=descriptor are equivalent
    
       -F     same as --follow=name --retry
    
       With  --follow  (-f),  tail  defaults to following the file descriptor,
       which means that even if a tail’ed file is renamed, tail will  continue
       to  track  its  end.   This  default behavior is not desirable when you
       really want to track the actual name of the file, not the file descrip-
       tor (e.g., log rotation).  Use --follow=name in that case.  That causes
       tail to track the named file by reopening it periodically to see if  it
       has been removed and recreated by some other program.
    

    【讨论】:

      猜你喜欢
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      • 2021-02-14
      • 1970-01-01
      • 2018-07-12
      • 2015-08-15
      • 1970-01-01
      相关资源
      最近更新 更多