sudo apt-get install logwatch
sudo yum install logwatch
配置文件路径:/etc/logwatch/conf/logwatch.conf
(若为空则复制模板:/usr/share/logwatch/default.conf/logwatch.conf
)。
关键参数:
MailTo
:接收报告的邮箱(支持多个,逗号分隔)。Detail
:报告详细程度(Low
/Med
/High
或数字0-10,数字越大越详细)。Range
:日志日期范围(All
/Yesterday
/Today
)。Service
:指定服务(如sshd
、httpd
),-服务名
表示排除该服务。Output
:输出格式(mail
/stdout
/file
)。logwatch --range today --detail high --output mail
。logwatch --service sshd --detail high --print
。logwatch --range yesterday --detail med --output file --filename /tmp/logwatch.html
。安装后默认在/etc/cron.daily/0logwatch
生成定时任务,可通过crontab -e
修改执行时间。
sendmail
/postfix
),否则无法发送邮件。/usr/share/logwatch/scripts/services/
,需遵循工具规范。参考来源: