//Linux/シェルスクリプト/プロセスダウンの監視
簡単なプロセスの監視スクリプトです。
キーワード指定したプロセスがダウンするとメールします。
キーワード指定は部分一致検索。キーワードはいくつでも設定可能です。
#!/bin/sh
#
# --- check_process.sh ---
# cron設定 10分ごとに実行
# 0,10,20,30,40,50 * * * * /home/myuser/check_process.sh > /dev/null 2>&1
# プロセスがダウンした際のメールの宛先指定
#
# MAILTO="[メールアドレス]"
MAILTO="myuser@localhost"
# 監視するプロセス指定
# ※ps -ef で表示されるプロセスによるキーワード指定
#
# echo "[監視プロセス]" >> tmp.txt
rm -R tmp.txt
touch tmp.txt
#echo "sendmail" > tmp.txt
#echo "named" >> tmp.txt
#echo "httpd" >> tmp.txt
#echo "xinetd" >> tmp.txt
#echo "ftpd" >> tmp.txt
echo "tomcat" >> tmp.txt
echo "httpd" >> tmp.txt
echo "postmaster" >> tmp.txt
#ここから処理(psでチェック)
ps -ef > tmpps.txt
for PROCESS in `cat tmp.txt`
do
cat tmpps.txt | grep -v "grep" | grep $PROCESS > /dev/null
FLAG=`echo $?`
if [ $FLAG -ne 0 ]
then
mail -s "*** Process $PROCESS Down!!***" $MAILTO < tmpps.txt
fi
done
rm -f tmp.txt 2> /dev/null
rm -f tmpps.txt 2> /dev/null