![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirect Standard Output Multi-Process | djodjo | High Level Programming | 5 | 10-01-2008 05:09 AM |
| [BASH] redirect standard error and use it inside | Pescator | Shell Programming and Scripting | 2 | 03-03-2008 09:20 AM |
| redirect only the standard error output to mail | barkath | Shell Programming and Scripting | 3 | 02-08-2008 08:41 PM |
| Question from a newbie. How to redirect standard output | ndemos | UNIX for Dummies Questions & Answers | 1 | 07-27-2007 10:28 AM |
| Error: Internal system error: Unable to initialize standard output file | firkus | UNIX for Dummies Questions & Answers | 2 | 10-25-2005 03:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
redirect standard error into log file
Hi,
I am new in shell scripting. Can anyone point out what wrong of below script. If I want the error output to "sqlerror.log" and database pool data output to "bulk_main.dat". Right now, the below script, if successful execute, the data will output to bulk_main.dat && sqlerror.log both file. thanks & regards. -------------------script---------------------------------- #!/usr/bin/ksh DB=TrialV01 USER=scott PASS=tiger sqlplus -S $USER/$PASS@$DB << EOF > sqlerror.log 2>&1 spool bulk_main.dat set pages 0 SET HEAD off FEEDBACK off VERIFY off ECHO off SERVEROUTPUT off; select filename , module from MXS_BULK_MAIN ; spool off; quit; EOF if [ $? -eq 0 ] then echo Successful else echo Failed fi |
|
||||
|
see this
Actually you are redirecting both the standard output and standard error stream to sqlerror.log. If you want to redirect only the error stream, try this.
sqlplus -S $USER/$PASS@$DB << EOF 1>/dev/null 2>sqlerror.log This redirects the standard output to a null file. If you want the output, just remove the 1>/dev/null. |
|
||||
|
not successful
sorry..it's fail. The script still will would not redirect the error "sqlerror.log" .
when have error, the error log is capture to "bulk_main.dat " ------------------------------------------------ sqlplus -S $USER/$PASS@$DB << EOF 1>bulk_main.dat 2>sqlerror.log set pages 0 set term off SET HEAD off FEEDBACK off VERIFY off ECHO off SERVEROUTPUT off; select filename , module from MXS_BULK_MAIN ; quit; EOF |
|
||||
|
see why
The first thing is that you are spooling the output of the query to the file bulk_main.dat. So, even if the query fails, the resulting output of the failure would go into the spooled file.
If you have to check for errors, the first form given by you sqlplus -S $USER/$PASS@$DB << EOF > sqlerror.log 2>&1 will work fine. After the execution, check for errors in the log file and then decide to use the output file. IF you find errors in the logfile, donot continue and come out. grep -i ora- sqlerror.log>/dev/null && (echo "Ora Error";exit -1) grep -i sp2 sqlerror.log >/dev/null && (echo "SQL Error";exit -1) I hope it is clear. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|