为什么无法发送轮换日志信息的电子邮件?

为什么无法发送轮换日志信息的电子邮件?

我希望 logrotate 将轮换的日志信息发送到我的电子邮箱[email protected]

cat  /etc/logrotate.d/myservice.log

/var/log/myservice.log {
    size=1M
    dateext
    daily
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
    echo | mutt -s "Log files for `date`"   [email protected] -a  /var/log/myservice.log
    create 644 root root
    postrotate
        /usr/bin/killall -HUP rsyslogd
    endscript
}

为何轮转日志信息无法发送到我的雅虎邮箱?

答案1

尝试这个:

/var/log/myservice.log {
    size=1M
    dateext
    daily
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
    create 644 root root
    postrotate
        /usr/bin/killall -HUP rsyslogd     
        /bin/echo | mutt -s "Log files for `date`"   [email protected] -a  /var/log/myservice.log
    endscript
}

您可能需要指定“mutt”的完整路径,并调整日志的名称,正如 Esa 所说,它可以是 log.1,也许是 log.1.gz。

顺便说一句,rsyslogd 本身足以处理日志轮换,方法是在需要轮换时调用您提供的脚本。您可以将邮件添加到脚本中。例如。https://www.rsyslog.com/doc/v8-stable/tutorials/log_rotation_fix_size.html,我引用一下:

# start log rotation via outchannel
# outchannel definition
$outchannel log_rotation,/var/log/log_rotation.log, 52428800,/home/me/./log_rotation_script
#  activate the channel and log everything to it
*.* :omfile:$log_rotation
# end log rotation via outchannel

相关内容