I'm using logrotate to rotate my log files.
I've set it up to create new logfiles every week.
However I would like it to first mail me the logfiles as attachments.
The /var/log/httpd
file currently contains:
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
firstaction
{I think I need to mail the logfiles here???}
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
Is it possible to do what I want?
If so: what do I need to add to firstaction
for it to:
- mail me the logfiles (
/var/log/httpd/*log
) as attachment using sendmail - add some subject to the mail, e.g.:
HTTPD logfiles {week #}
Best Answer
If I understand your question correctly, there's a logrotate option that will do what you want. Simply add
mail user@yourdomain.com
as one of the configuration options, like this:This will mail you the log files that are about to be rotated.
Perhaps you've tried this and it didn't quite do what you need. In that case, I think you're on the right track for the most part. However, invoking sendmail directly isn't the right approach when you're trying to send a message with attachments. To quote the sendmail FAQ:
If you have the mail user agent mutt (or can install it), it should be able to do what you want. Try something like this:
Note also in your example configuration file you're missing the
endscript
for yourfirstaction
command.