logwatch設定
- 一般ユーザでもlogwatchが使えるようにTmpDirは/tmpを指定する。
/etc/logwatch/conf/logwatch.conf
+ TmpDir = /tmp
Output = mail
Format = text
MailTo = my@mailaddr.co.jp
MailFrom = Logwatch
Range = Yesterday
Detail = High
Service = All
mailer = "/usr/sbin/sendmail -t"
fcronで実行するスクリプト作成
ArchLinux用
- journalctlでログを出力し、logwatchで解析
- mkdir -p ~/cron/logs/
$HOME/cron/logwatch.sh
# !/bin/sh
set -eu
YESTERDAY=`date -I --date=yesterday`
LANG=C journalctl --since="$YESTERDAY" --until="$YESTERDAY 23:59:59" \
> ~/cron/logs/messages.$YESTERDAY
/usr/sbin/logwatch --logdir ~/cron/logs/ \
--logfile messages \
--range Yesterday
gzip -f ~/cron/logs/messages.$YESTERDAY
CentOS7用
$HOME/cron/logwatch.sh
# !/bin/sh
set -eu
/usr/sbin/logwatch --range Yesterday
fcronに登録
chmod +x ~/cron/logwatch.sh
fcrontab -e
# 0 9 * * * $HOME/cron/logwatch.sh