Logwatchでメールの送信元を設定する

投稿日: 2011年06月09日 更新日: 2017年07月22日

RHEL/CentOSの4.xか5.xかでLogwatchのバージョンが異なり、送信元の変更方法が異なる。

5.xは設定ファイルの変更で可能。

4.xのLogwatchでは設定で変更できないため、スクリプトを変更する必要がある。

5.xの場合。設定ファイルに下記を追記するだけ。

# /etc/logwatch/conf/logwatch.conf に追記
MailTo = root@example.com
mailer = "sendmail -t -f root@example.com"

テストするには下記のようにコマンドを発行する。

# /etc/cron.daily/0logwatch

もし、何も送られない場合は送られなる内容を表示してみる(–print)。範囲も全部(–range all)で。

もしかしたら送信すべき内容が無いため送られていないかもしれない為。

# /etc/cron.daily/0logwatch --range all --print

4.xの場合。まず設定ファイルを書き換える。

# mailer = /bin/mail <-- コメントアウト
mailer = "sendmail -t -f root@example.com"
MailFrom = root@example.com

次にスクリプトを書き換える。スクリプトのバージョンによっては変更箇所が微妙に異なるため注意。下記はLogwatch 5.2.2 (released 06/23/04)での変更箇所。

$ diff 00-logwatch /etc/cron.daily/00-logwatch
679c679,689
<          open(OUTFILE,"|$Config{'mailer'} -s \"LogWatch for $Config{'hostname'}\" " . $Config{'mailto'}) or die "Can't execute /bin/mail\n";
---
>          #open(OUTFILE,"|$Config{'mailer'} -s \"LogWatch for $Config{'hostname'}\" " . $Config{'mailto'}) or die "Can't execute /bin/mail\n";
>
>          open(OUTFILE,"|$Config{'mailer'}") or die "Can't execute /bin/mail\n";
>
>          print OUTFILE "From: $Config{'mailfrom'}\n";
>          print OUTFILE "To: $Config{'mailto'}\n";
>          print OUTFILE "Subject: LogWatch for $Config{'hostname'}\n\n";
>          if (($Config{'splithosts'} eq 1) && ($Config{'multiemail'} eq 0)) {
>             print OUTFILE "Reporting on hosts: @hosts\n";
>          }

名前:宮内 はじめ

Code for Nagoya名誉代表

E2D3名古屋支部長

プログラマーです。GISやデータビズが好きです。このサイトは宮内の個人的なメモです。

プロフィール

お問い合わせ