Using logrotate to rotate logs daily. Want to email the log. The rotate is working as expected, but logs are not being emailed. I am able to generate emails from PHP using mail(), but I am not sure if I need to set up something else as a service for logrotate. I am also not sure where the logrotate mail error would be reported.
Thanks.
Details:
On Ubuntu 14.04.4 (Digital Ocean LAMP), using logrotate with /etc/logrotate.d/apache2 (config):
/var/www/html/logs/my.log {
daily
missingok
rotate 360
compress
delaycompress
notifempty
create
sharedscripts
mail me@mydomain.com
mailfirst
}
Best Answer
Make sure you can send mail
Can your system send email? You'll likely want Postfix installed and configured. Probably to relay to another host identified by
relayhost
in/etc/postfix/main.cf
.You can test with
echo test | mail -s test user@example.com
./usr/bin/mail
is the command logrotate uses by default, so if things work in your test, logrotate should work too.logrotate
man page excerpt:About /usr/bin/mail
/usr/bin/mail
is a symlink (example from Ubuntu 16.04):On this system, you could install the
mail
command withI checked and this package does exist in Ubuntu 14.04 so I think you're good. I think you can also use the
mailutils
package as an alternative.Check your mail log (
/var/log/mail.log
). You should see exactly what is happening with the messages if they are making it to Postfix.You can debug
logrotate
if the above isn't the problemYou can run logrotate manually and even apply
-v
for verbose mode and-f
for force. You should see what's going on.