我希望使用 logrotate 将我的日志发送到我的邮箱

ler*_*son 5 email logrotate

严格来说,这不是一个关于编程的问题,而是一个日志处理问题。

反正。我的公司有多个客户,每个客户都有一组日志,我非常希望通过电子邮件将这些日志发送给我。

现在,另一个先决条件是它们由简单的 HTML 突出显示。

所有这一切都很好,我已经设法为给定的日志类型制作了一个亮点。所以,我所做的是使用logrotate's 的prerotate东西将日志作为电子邮件发送。例子:

/var/log/a.log /var/log/b.log {
  日常的
  错过了
  复制截断

  预旋转
    /usr/bin/python /home/foo/hilight_logs /var/log/{a,b}.log | /usr/sbin/sendmail -FLog\ mailer -fnoreply@client.com me@mydomain.com
  尾标
}

这种方法的问题基本上很logrotate糟糕:它会为说明符中指定的每个日志文件运行命令,据我所知,没有办法知道正在处理哪个日志文件。(无论如何,这不会真正有帮助。)

除了logrotate在不同的机器上重复最多 10 次之外,我唯一能做的就是每晚都被日志垃圾邮件所困扰。我今天厌倦了,所以我问。

Chr*_*ian 3

尝试替换prerotatefirstaction. 这样,您的邮件命令将仅对块中定义的所有日志执行一次。

这是手册页中的文本:

firstaction/endscript
          The lines between firstaction and endscript (both of which must appear on lines by themselves) are executed once before all log files that match the
          wildcarded pattern are rotated, before prerotate script is run and only if at least one log will actually be  rotated.  These  directives  may  only
          appear inside a log file definition. If the script exits with error, no further processing is done. See also lastaction.
Run Code Online (Sandbox Code Playgroud)