Swatchの導入(シェルスクリプトで)
■04/02/07
まず、「Swatch」本体とPerlモジュールが必要になります。
swatch-3.0.8.tar.gz
Date-Calc-5.3.tar.gz
File-Tail-0.98.tar.gz
TimeDate-1.16.tar.gz
Time-HiRes-1.48.tar.gz
これらを「/root/Down/swatch」に用意しておきます。
次に 「.swatchrc_message」というファイルを作成します。内容は以下のようになります。意味合いとしては、「swatch」を作動させ、ログが書き込まれたときに「/」で囲まれた文字列にマッチした内容があった場合、「ビープ音」を鳴らしたり、指定したアドレスにメールを送信したりすることができます。
下の例では、「/var/log/message」に「authentication
failure」 という文字列を含んだログが書き込まれると、「ビープ音」を3回鳴らし、「aaaa@bbb.ccc.com」あてにそのログを送信します。
watchfor /authentication failure/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /reject/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /Rejected/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /nessus@/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /unreachab/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /not allowed/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /unknown/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /debug/
bell 3
watchfor /peer died/
bell 3
watchfor /not connected/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /Connection reset/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /Can't|Cannot/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /NULL/
bell 3
watchfor /Bad|bad/
bell 3
watchfor /denied/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /FAILED|failed|failure|illegal/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /Broken pipe/
bell 3
watchfor /EXT2-fs warning/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /deny/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /INVALID|REPEATED|INCOMPLETE/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /(panic|halt)/
bell
mail=aaaa@bbb.ccc.com
「.swatchrc_secure」というファイルを作成します。内容は以下のようになります。
watchfor /Failed password/
bell 3
mail=aaaa@bbb.ccc.com
watchfor /Invalid/
bell 3
mail=mail=aaaa@bbb.ccc.com
次にインストールシェルスクリプトを作成します。ファイル名はここでは「swatch.sh」としておきます。
#!/bin/bash
DateCalc="Date-Calc-5.3"
FileTail="File-Tail-0.98"
TimeDate="TimeDate-1.16"
TimeHiRes="Time-HiRes-1.48"
swatch="swatch-3.0.8"
#
cd /root/Down/swatch
# 各モジュールのインストール
#Date-Calc
tar zxfv ${DateCalc}.tar.gz
cd ${DateCalc}
perl Makefile.PL
make
make test
make install
cd ../
#File-Tail
tar zxfv ${FileTail}.tar.gz
cd ${FileTail}
perl Makefile.PL
make
make test
make install
cd ../
#TimeDate
tar zxfv ${TimeDate}.tar.gz
cd ${TimeDate}
perl Makefile.PL
make
make test
make install
cd ../
#Time-HiRes
tar zxfv ${TimeHiRes}.tar.gz
cd ${TimeHiRes}
perl Makefile.PL
make
make test
make install
cd ../
#Swatch
tar zxfv ${swatch}.tar.gz
cd ${swatch}
perl Makefile.PL
make
make test
make install
#
cd /etc
mkdir swatchrc
cp /root/Down/swatch/.swatchrc_message /etc/swatchrc/.swatchrc_message
cp /root/Down/swatch/.swatchrc_secure /etc/swatchrc/.swatchrc_secure
#
echo " " >> /etc/rc.local
echo 'swatch -c /etc/swatchrc/.swatchrc_secure -t /var/log/secure
&' >> /etc/rc.local
echo 'swatch -c /etc/swatchrc/.swatchrc_message -t /var/log/messages
&' >> /etc/rc.local
「/root/Down/swatch」以下には、
swatch-3.0.8.tar.gz
Date-Calc-5.3.tar.gz
File-Tail-0.98.tar.gz
TimeDate-1.16.tar.gz
Time-HiRes-1.48.tar.gz
.swatchrc_message
.swatchrc_secure
swatch.sh
を用意して、ターミナル上で
# cd /root/Down/swatch
# ./swatch.sh
と打ち込むと自動的にインストールが始まります。
(注意)
「/etc/rc.local」の
touch /var/lock/subsys/local
echo "nameserver 127.0.0.1" >
より下に
swatch -c /etc/swatchrc/.swatchrc_secure -t /var/log/secure &
swatch -c /etc/swatchrc/.swatchrc_message -t /var/log/messages &
を 書き込むと、起動したときに作動しないようです。
<Pre Next>