这是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
注意:我已经注释掉了一些未使用的行。
谢谢。