Problem with IF - CAT - GREP in simple shell script

Hi all,

Here is my requirement

I have to search 'ORA' word in out.log file,if it is present then i need to send that file (out.log) content to some mail id.If 'ORA' word is not in that file then i need to send 'load succesful' message to some mail id.

The below the shell script is not giving expected result.Please help me to get correct script

if [{cat out.log | grep -c "ORA"}  -eq  1]
then
echo out.log
   exit 0
 else
   echo "Load Succes"
fi

Regards
Mak

grep -c "ORA" outlog 1>/dev/null

if [ $? -eq 0 ]  ## some oracle error
then
echo out.log  
######## can mail to the user 
   exit 0
 else
   echo "Load Succes"
###### can mail to the user 
fi

check the mail command and it's option.

Hi Panyam,

Your script is nice.  But instead of 

grep -c "ORA" outlog 1>/dev/null

You can use

grep -q "ORA" outlog

This has the advantage that it will not write any thing on standard out put so no re-direction is required. Also it will exit with success on the first occurance of "ORA", will not search file till the end which is not required.

thanks a lot Panyam

This is interesting... I would suggest using -w option also i.e. grep -q -w to make sure ORA is the same as we want.

Thanks Ranjith for the efficient idea :slight_smile: