script to check error

I have below script to check the word in the driectory /ora_tmp , there are many files in this directory , if the word "error" is exist in any file within 5 day , then send the mail to ora-usr@mydomain.com about which file have this word and the "error" statement , now , if I want

  1. if there is no "error" word existed in any file , then DO NOT send the mail ;
  2. send "error" statement to user one time only , that mean , only inform user the "error" statement one time , if there are same "error" statement within 5 days , send the mail to user one time only ( the user need to know the same error one time only ) . can advise how can I change it ? thx.

FILE=/tmp/error ; export FILE

mailfile=/tmp/mailfile ; export mailfile

find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE

cat $FILE >> $mailfile

echo $mailfile
mail ora-usr@mydomain.com < $mailfile

Hi ust,

find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE

After this, check the size of the file using test command

if [ -s $FILE ] then
#FILE exists and has a size greater than zero
# To send the mail only once use sort and uniq commands
sort $FILE | uniq >> $mailfile
mail ora-usr@mydomain.com < $mailfile

else
# Do nothing(which means there is no error)
fi

Hope this will give you some idea to proceed!:b:

Regards,
Chella

thx reply ,

I modified the script as below , it can send nodify mail only when there is error ,
but I am not too understand the suggestion above , my requirement is " to send "error" statement to user one time only , that mean , only inform user the "error" statement one time , if there are same "error" statement within 5 days , send the mail to user one time only ( the user need to know the same error one time only ) . can advise ? thx

FILE=/tmp/error ; export FILE
mailfile=/tmp/mailfile ; export mailfile
find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE
if [ -s $FILE ] ; then
cat $FILE >> $mailfile
echo $mailfile
mail ora-usr@mydomain.com < $mailfile