1

this is my scash script

 query="select * from blabla;"    
    sqlplus64 -S /nolog <<ENDOFSQL>>errorLog.txt 
               CONNECT username/pwd@domainName:1521/serviceName
               whenever sqlerror exit sql.sqlcode;
               $query 
               exit;
    ENDOFSQL
               ERRORCODE=$?

                   if [ $ERRORCODE -eq 0 ];
                      then
                          echo  "$query" >> "sqlTemp.SQL"
                          echo  -e  "$query \n this query is successful" 

                      else
                          echo -e "$query \nthis query has  error- check the log file for detail" 

                   fi

My requirement is to collect only the error, instead I am getting all error and successful data.

I have tried

1.sqlplus64 -S /nolog <<ENDOFSQL2>>errorLog.txt 
2.sqlplus64 -S /nolog <<ENDOFSQL 2>&1>errorLog.txt 

I can't use a pipe as errorcode will not receive the desired error code.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250

1 Answers1

1

use the bash redirection

Script.sh 2> Error.log
SHW
  • 14,454
  • 14
  • 63
  • 101