Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

Configuring Logwatch for automated log analysis on CentOS

Logwatch turns verbose system logs into scheduled email or terminal reports, giving CentOS administrators a quick view of security, service and disk activity. Its filters and ranges support automated log analysis for both small offices and managed infrastructure.

This guide covers CentOS 7 and CentOS Stream, configuration paths, unattended delivery and safe validation. CentOS 7 reached end of life in June 2024, but legacy appliances still appear in Australian logistics and managed-service estates, where controlled reporting can support migration.

Preparing the CentOS host for log analysis

Start on a test host and confirm its operating system, repository state, clock and free space. For legacy CentOS 7, use an approved Vault or internal mirror rather than reviving obsolete repositories. CentOS Stream 8 and 9 should use current dnf repositories.

Identify relevant syslog and service logs, including /var/log/secure, /var/log/messages, /var/log/cron and service files. For teams in Sydney, Melbourne and Brisbane, document whether cron follows local time or UTC; AEST and AEDT changes complicate cross-site coordination.

Installing Logwatch and checking dependencies

On CentOS Stream, run sudo dnf install -y logwatch. If no package matches, enable the current EPEL repository for that exact Stream release and retry. On CentOS 7, use sudo yum install -y logwatch through a maintained mirror. Keep SELinux enforcing during installation.

Verify with rpm -q logwatch and command -v logwatch. Logwatch is a Perl program, so check perl -v as well. Important paths are /etc/logwatch.conf, service rules in /etc/logwatch.d, and the packaged launcher at /etc/cron.daily/logwatch. Review them before editing so upgrades can replace defaults cleanly.

Configuring report scope and details

Use --range today or --range yesterday, and add --service sshd for a focused rule. A dedicated file under /etc/logwatch.d/, owned by root, can contain:

--service=sshd
--range=today
--details

Include --details only when event-level evidence is required; test each rule manually before scheduling it.

Treat report content as untrusted evidence. A service rule may copy a URL from an access log; an entry pointing to met bonus slots is something to investigate, not a destination to trust. This distinction matters when administrators work through queued alerts.

Keep reports private. Logwatch can expose IP addresses, usernames and URLs, so use encrypted mail and store redirected output outside web-served directories with restrictive permissions. Start with summaries and broaden details only for named recipients.

Comparing delivery methods and scheduling reports

A single report can be inspected locally, sent by email or filtered to one service. These methods have different dependencies, so choose the simplest approach that meets the monitoring requirement.

Delivery method Best suited to Example Operational requirement
Manual preview Testing a rule sudo logwatch --range today --output stdout Check the output interactively
Email Routine summaries sudo logwatch --range today --output mail --mailto ops@example.com.au A working local mail transfer agent
Service filter Focused investigation sudo logwatch --service sshd --range today --output stdout A matching Logwatch service rule
Cron entry Unattended delivery /etc/cron.d/logwatch Correct ownership and one scheduler

Use one scheduler only. For daily delivery at 07:00, create /etc/cron.d/logwatch as root with mode 0644:

0 7 * * * root /usr/bin/logwatch --range today --output mail --mailto ops@example.com.au

The command needs a working local mail transfer agent, such as Postfix, that can invoke /usr/sbin/sendmail; ensure sudo systemctl enable --now crond is active. If /etc/cron.daily/logwatch remains enabled, configure that job or disable the duplicate through change control. Cron follows the host timezone, so document whether 07:00 means Sydney time or UTC.

Security controls and daily operating checks

Keep daily checks lightweight and repeatable. A successful terminal run confirms parsing, a matching cron entry confirms scheduling, and an outbound mail test confirms delivery. Where logs contain personal information, align report retention with the Privacy Act 1988 and internal security requirements.

Use these checks to confirm that reporting is operational:

Before changing report scope, use a short review checklist:

Troubleshooting common reporting failures

When no email arrives, run the same Logwatch command in a terminal, inspect /var/log/cron and /var/log/maillog, and confirm that a local mail transfer agent can invoke /usr/sbin/sendmail. Test outbound delivery separately, because a successful report proves only that Logwatch created its output.

Permission denials usually point to SELinux rather than ordinary ownership. Use sudo ausearch -m AVC -ts recent, then compare the audit message with guidance on RHEL SELinux web policies and adapt the labels for the CentOS release; disabling enforcement can hide a broader web-server problem.

Logwatch is most reliable with traditional text log files. On journald-only services, use journalctl to confirm the event and configure a suitable file source or companion export. Verify the requested range as well, because today omits yesterday’s events and can look like data loss near midnight.

Rolling out a monitored reporting routine

Standardise the main configuration, service rules, recipients and retention settings through your configuration-management system. Keep local edits out of the package-owned cron launcher, record every override in the operations runbook, and grant reporting access only to required log files. This creates repeatable behaviour across Australian offices without exposing full logs to every user.

Begin with one pilot host using the same Stream release as the fleet and compare its report with the current manual process. The next deployment action is to run one verified report on that pilot and save the timestamped output as the acceptance baseline before extending the package and schedule.