The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-09-2006
epall epall is offline
Registered User
  
 

Join Date: May 2006
Posts: 18
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
  #2 (permalink)  
Old 05-09-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
add this

add the below before the sql
set term off
and see whether you are getting the required functionality.
  #3 (permalink)  
Old 05-09-2006
epall epall is offline
Registered User
  
 

Join Date: May 2006
Posts: 18
set term off

still the same error.
set term off didn;t help.
  #4 (permalink)  
Old 05-09-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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.
  #5 (permalink)  
Old 05-09-2006
epall epall is offline
Registered User
  
 

Join Date: May 2006
Posts: 18
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
  #6 (permalink)  
Old 05-09-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0