My error is not being caught or handled

Hi,

I my ksh script I have the following:

##--Checking the spool file for errors
NumberOfErrors=`cat $CurrSpoolFile | grep " ORA-[0-9]" | wc -l`

my logfile shows this:

PL/SQL procedure successfully completed.

PL/SQL procedure successfully completed.

BEGIN sys.dbms_stats.export_schema_stats('INFOMAT','STATTAB','RIX230909'); END;

*
ERROR at line 1:
ORA-20000: Table "INFOMAT"."STATTAB" does not exist or insufficient privileges
ORA-06512: at "SYS.DBMS_STATS", line 5158
ORA-06512: at "SYS.DBMS_STATS", line 5185
ORA-06512: at "SYS.DBMS_STATS", line 5587
ORA-06512: at line 1

$NumberOfErrors should give me a result of 5 however when I run the following:

# Populating the ScriptStatus variable
ScriptStatus="There were ${IndexesBefore} Indexes before the script and ${IndexesAfter} Indexes after the script -- SQL has 
generated ${NumberOfErrors} ORA errors"

  if [[ ${NumberOfErrors} -gt 0 ]] || [[ ${IndexesBefore} -ne ${IndexesAfter}  ]]
  then
        echo "Script Errors... "                                    >> $CurrLogFile
...
...

I get a value of 0. Can anyone see why? When I run the grep command straight from the command line I get my expected results as such:

>cat Rebuild_ix_COMP.log.curr | grep "ORA-[0-9]" | wc -l
      10

I can't see anything that stands out here...I am so confused...PLEASE HELP!

---------- Post updated at 03:19 PM ---------- Previous update was at 03:14 PM ----------

I also tried this as well:

NumberOfErrors=cat Rebuild_ix_COMP.log | grep " ORA-[0-9]" | wc -l
ksh: Rebuild_ix_COMP.log: cannot execute
       0

That "ORA-" message starts from the first column. Remove the space to the left of it.

BTW, this command:

cat Rebuild_ix_COMP.log | grep " ORA-[0-9]" | wc -l

is worthy of the Useless Use of Cat Award.

Try:

grep -c ^ORA- your_log_file

tyler_durden