redirect standard error into log file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers redirect standard error into log file
# 1  
Old 05-09-2006
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  
Old 05-09-2006
add this

add the below before the sql
set term off
and see whether you are getting the required functionality.
# 3  
Old 05-09-2006
set term off

still the same error.
set term off didn;t help.
# 4  
Old 05-09-2006
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  
Old 05-09-2006
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  
Old 05-09-2006
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.
# 7  
Old 05-09-2006
thanks.

I think I know how to do already.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Redirect Standard Error to /dev/null is not working.

Hello. When I run a .ksh that contains the command below, and there is no file available in the source location the "FILE_NAME_*.CSV not found" error is still being displayed. FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null. This is interfering with the rest... (4 Replies)
Discussion started by: jimbojames
4 Replies

2. Shell Programming and Scripting

How redirect standard output to a file

Hi guys, i have a script named purgeErrors.ksh, when i execute this script i need to redirect the output to a log file in the same directory, how can i do that ?? -- Aditya (5 Replies)
Discussion started by: chaditya
5 Replies

3. UNIX for Dummies Questions & Answers

Redirect Standard output and standard error into spreadsheet

Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway? Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Discussion started by: killaram
6 Replies

4. Shell Programming and Scripting

Redirect standard error to input of other process, 2| ?

Hello, I would like to know if there is a shell in which operations such as 2| (redirect standard error of one process to the standard input of another one) exist? I know it is possible to do it in bash with things like: (process 2>&1) | other_process but I find it a bit intricate when... (3 Replies)
Discussion started by: chlorine
3 Replies

5. Programming

Redirect Standard Output Multi-Process

Hi, I'm trying to compile the following code: /************** Begin <test.c> ***************/ /* * Compiled with: gcc -Wall -o test test.c */ #include <stdio.h> #include <unistd.h> int main(void) { printf("I'm process %d, son of %d \n", getpid(), getppid()); ... (5 Replies)
Discussion started by: djodjo
5 Replies

6. HP-UX

How to Redirect the error messages from Syslog file to our own Application Log File

Hello, I am New to Unix. I am Using HP-UX 9000 Series for my Application. I am Currently Facing an Issue that the error messages are being written in the syslog file instead of the Application Log File. The Codes for that Syslog.h is written in Pro*C. I want to know how to Redirect these... (3 Replies)
Discussion started by: balasubramaniam
3 Replies

7. Shell Programming and Scripting

[BASH] redirect standard error and use it inside

Hi all, Maybe my question is too simple but till now i couldn't figure about a solution :( I have a bash script scheduled in cron: <cron time parameters> my_script.sh > result.log 2>&1 By this way i can have standard output and standard error in my result.log file Now i want my script... (2 Replies)
Discussion started by: Pescator
2 Replies

8. Shell Programming and Scripting

redirect only the standard error output to mail

I'm writing a script using file descriptor 2 (std error) to send an email only if the command fails or errors out but the script always emails me irrepective of whether it fails or not. It will not email the /tmp/check.error file output if doesn't error out just the mail with the subject "Cannot... (3 Replies)
Discussion started by: barkath
3 Replies

9. UNIX for Dummies Questions & Answers

Question from a newbie. How to redirect standard output

I have a program that is sending error text to the console and I need to redirect that output to a log file. I'm brand new to Unix and don't know how to do this. Any direction would be greatly appreciated. (1 Reply)
Discussion started by: ndemos
1 Replies

10. UNIX for Dummies Questions & Answers

Error: Internal system error: Unable to initialize standard output file

Hey guys, need some help. Running AIX Version 5.2 and one of our cron jobs is writing errors to a log file. Any ideas on the following error message. Error: Internal system error: Unable to initialize standard output file I'm guessing more info might be needed, so let me know. Thanks (2 Replies)
Discussion started by: firkus
2 Replies
Login or Register to Ask a Question