Last active
December 10, 2015 19:39
-
-
Save onigra/4482612 to your computer and use it in GitHub Desktop.
簡単なログ監視用のシェルスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# メール送信設定 | |
_to="[email protected]" | |
_from="[email protected]" | |
# メール件名設定 | |
_hostname=`hostname` | |
_application="AppName" | |
_subject="Fatal error!!" | |
_title="[${_application}][${_hostname}]${_subject}" | |
# エラー条件 | |
_error_conditions="ERROR" | |
# ログファイルをtailし、_error_conditionsの条件にヒットしたらメールを送信する | |
mail_alert() { | |
while read i | |
do | |
echo $i | grep -q ${_error_conditions} | |
if [ $? = "0" ];then | |
echo $i | /usr/sbin/sendmail -t << EOF | |
MIME-Version: 1.0 | |
Content-Type: text/plain; charset=iso-2022-jp | |
From: ${_from} | |
To: ${_to} | |
Subject: ${_title} | |
Data Replication Failed | |
--- | |
$i | |
--- | |
Please check with a administrator for details. | |
EOF | |
fi | |
done | |
} | |
tail -n 0 --follow=name --retry $1 | mail_alert |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment