Capture all error message in Log file and send the Log file by email

Hi
I have a requirement to write a script to capture all errors in a Logfile and send the file in email.
If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS.

So I created a Log file and put the Appropriate message to Logfile.
I check $? !=0 then I write "**ERROR** happened in this task" to Log file.

At the end of the script I do

But I get Null in $Error_Count. So I am not able determine how to know if there are any ERROR.
But when I open the Logfile after the script finishes I see **ERROR** present in Logfile. Can anyone suggest me how to capture all error message and send in Logfile.

Thanks and Regards
Digambar

I guess * is expanded .. try below:

grep '\*\*ERROR\*\*' LogFile | wc -l 

Also try same command on command line to see what you get ...
with newer grep it will show you what is matched in different colour .

grep --color=auto

Hi Chakrapani
Thanks for your reply, Do you think the grep will work even if it is buffer. Because the script is wrtiing to Logfile and I will be checking the same Logfile in the script. Even if for me ** is not imporant. But wanted to search by a pattern to find if there a error in Logfile.
Do you think the way I am doing is ok or is there a better way to capture all the errors.

Thanks
Dgmm