Why
Your server generates numerous logs that contain important security and operational information. Unless you plan on checking your server logs daily, you need an automated way to receive email summaries. logwatch scans system log files and provides easy-to-read summaries.How It Works
logwatch scans system log files and summarizes them into readable reports. It uses service files (located in/usr/share/logwatch/scripts/services) to understand how to parse different log types.
The configuration file /usr/share/logwatch/default.conf/logwatch.conf specifies default options that can be overridden via command line arguments.
Goals
- logwatch configured to send daily email summaries of server status and logs
- Comprehensive coverage of all important system services and events
Notes
- Your server must be able to send emails for this to work
- The steps below configure daily reports. To change the schedule, modify the cron job and adjust the
rangeoption accordingly - If you followed the Gmail/Exim4 setup earlier, the long line issue mentioned in some guides has already been addressed
References
- https://sourceforge.net/projects/logwatch/
- https://www.digitalocean.com/community/tutorials/how-to-install-and-use-logwatch-log-analyzer-and-reporter-on-a-vps
- https://blog.dhampir.no/content/exim4-line-length-in-debian-stretch-mail-delivery-failed-returning-message-to-sender
Installation and Setup
Review configuration file
Review logwatch’s configuration file to understand the available options:Pay attention to these key settings:
Output- Where to send the report (stdout, mail, file)Format- Output format (text or html)MailTo- Email recipientRange- Time range to analyze (yesterday, today, all)Service- Which services to report on
Instead of modifying the configuration file, we’ll pass options as command line arguments in the cron job. This ensures your settings persist even if the config file is updated.
Configure email output
Modify The complete file should look like:
/etc/cron.daily/00logwatch to send HTML emails instead of stdout output.Find the execute line and change it to:Command Line Options
Useful logwatch options for manual runs:| Option | Description |
|---|---|
--output stdout | Display on screen |
--output mail | Send via email |
--format text | Plain text format |
--format html | HTML format |
--mailto [email protected] | Recipient email |
--range yesterday | Yesterday’s logs |
--range today | Today’s logs |
--range all | All available logs |
--service all | All services |
--service sshd | Only SSH logs |
Customizing Reports
You can customize which services logwatch monitors:Daily Automated Reports
Once configured, logwatch will run daily via cron and email you comprehensive log summaries. These reports help you:- Monitor system health and performance
- Detect security issues and intrusion attempts
- Track service status and errors
- Review disk space and resource usage
- Identify unusual system activity