Not strictly a question about programming as such, more of a log handling question.

Anyway. My company has multiple clients, and each of these clients have a set of logs that I'd rather much want to get sent to by e-mail to me.

Now, another prerequisite is that they're hilighted by simple HTML.

All that is very well, I've managed to make a hilighter for the given log types. So, what I do is I use logrotate's prerotate stuff to send the logs as an e-mail message. Example:

/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

The problem with this approach is basically that logrotate sucks: it'll run the command for every log file specified in the specifier, and to my knowledge there's no way to know which of the log files is being handled. (Which wouldn't really help anyway.)

Short of repeating the exact same logrotate up to 10 times on different machines, the only thing I can do is just to get bogged down with log spam every night. And I grew tired of it today, so I ask.

  • I know I could do this with just a crontab and putting the job run time definition right before logrotate, but for complicated reasons I'd rather not. – lericson Apr 11 '10 at 6:34
  • What is the question? All I get from reading it is that you don't want to do what you want to do. – John Gardeniers Apr 11 '10 at 8:53

try to replace prerotate with firstaction. this way your mail command will only be executed one time for all logs defined in a block.

this is the text from the man page:

          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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.