文字列をgrepして電子メール警告を送信するための監視シェルスクリプトのログ記録

文字列をgrepして電子メール警告を送信するための監視シェルスクリプトのログ記録

これはgrepうまくいきません

grep -i "`date --date='today' '+%b %e'`"/ora/n003/OSB2/WLS_OSB2-diagnostic.log | awk '{ $3=""; print}' | egrep -wi 'failed' >>  $MESSAGE

「失敗」という文字列を探して見つけたら、電子メールを送信する必要があります。しかし、そうしません。私の電子メールアドレスに送信される特定の文字列(この場合はログファイルの「FAILED」エラーメッセージ)である期待される応答を受け取りませんでした。これで空のメールコンテンツが表示されます。

完全なスクリプトは次のとおりです。

#!/bin/bash
clear

#turn on debug mode
set -x
for f in *
do
    file $f
done
#Set the variable which equal to zero

#LOG_PATH="/ora/n004/test//OSB2/WLS_OSB2-diagnostic.log"

#prev_count=0

#grep -i "failed" /ora/n004/test/OSB2/WLS_OSB2-diagnostic.log  | wc -w

grep -i "`date --date='today' '+%b %e'`"/ora/n004/test/OSB2/WLS_OSB2-diagnostic.log | awk '{ $3=""; print}' | egrep -wi 'failed' >>  $MESSAGE


#if [ "$prev_count" -lt "$count" ] ; then

# Send a mail to given email id when errors found in log

SUBJECT="WARNING: Errors found in log on "`date --date='today' '+%b %e'`""

# This is a temp file, which is created to store the email message.

MESSAGE="This is a test!!There is a timeout"

TO="[email protected]"

echo "ATTENTION: Errors are found in /ora/n004/test//OSB2/WLS_OSB2-diagnostic.log. Please Check with int team." >> $MESSAGE

echo  "Hostname: `hostname`" >> $MESSAGE

echo -e "\n" >> $MESSAGE

echo "+------------------------------------------------------------------------------------+" >> $MESSAGE

echo "Error messages in the log file as below" >> $MESSAGE

echo "+------------------------------------------------------------------------------------+" >> $MESSAGE

#grep -i "`date --date='today' '+%b %e'`"/ora/n004/test//OSB2/WLS_OSB2-diagnostic.log | awk '{ $3=""; print}' | egrep -wi 'failed' >>  $MESSAGE

mailx -s "$SUBJECT" "$TO" < $MESSAGE


#rm $MESSAGE

注:未使用の行の一部をコメントアウトしました。

ありがとうございます。

ベストアンサー1

おすすめ記事