我想我的日志发送到我的邮件与logrotate

不是严格的关于编程的问题,更多的是日志处理问题。

无论如何。 我的公司有多个客户端,每个客户端都有一套我想用电子邮件发送给我的日志。

现在,另一个先决条件是,他们被简单的HTML所淹没。

所有这一切都很好,我已经设法让给定的日志typeshilighter。 所以,我所做的是使用logrotateprerotate东西来发送日志作为电子邮件。 例:

 /var/log/a.log /var/log/b.log {
  日常
   missingok
   copytruncate

   prerotate
     / usr / bin / python / home / foo / hilight_logs /var/log/{a,b}.log |  / usr / sbin / sendmail -FLog \ mailer [email protected] [email protected]
   endscript
 }

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

在不同的机器上重复完全相同的logrotate不超过10次,我唯一能做的就是每天晚上都被日志垃圾邮件堵塞。 我今天厌倦了,所以我问。

尝试用第firstactionreplacefirstaction 。 这样你的邮件命令将只执行一次在块中定义的所有日志。

这是手册页中的文字:

 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.