Blog / Others/ Forward CentOS System Log Emails from /var/spool/mail/root to a Personal Inbox

Forward CentOS System Log Emails from /var/spool/mail/root to a Personal Inbox

CentOS 系统日志邮件通知配置:将 /var/spool/mail/root 邮件转发至个人邮箱

Configuring System Log Email Notifications in CentOS

In CentOS, system services (like logwatch, cron, etc.) send log summaries and execution reports by default to the local root user's mailbox at /var/spool/mail/root. For easier management, you can forward these notifications to an external personal email address.

Configure Logwatch to Send Emails to a Personal Address

logwatch is a powerful log analysis tool that periodically generates system log summaries and sends them via email. To change its recipient address:

  1. Open Logwatch's main configuration file with a text editor (e.g., vi):
    vi /usr/share/logwatch/default.conf/logwatch.conf
  2. Locate the line MailTo = root.
  3. Change it to your personal email address, for example:
    MailTo = [email protected]
  4. Save and exit the editor.

Additional Configuration and Notes

Other services (like cron) also rely on the system's Mail Transfer Agent (MTA, such as sendmail or postfix) for email notifications. Ensure your MTA is correctly configured to send mail to external networks.

To forward all mail sent to the local root user to an external address, you can configure the system's mail aliases. Edit the file /etc/aliases and add the line:

root: [email protected]

Then run the command newaliases to apply the changes.

Verify the Configuration

After configuration, send a test email to verify:

echo 'Test mail from CentOS' | mail -s 'Test Subject' root

Wait a moment and check your personal inbox for the test message.

Post a Comment

Your email will not be published. Required fields are marked with *.