sqlplus error output to different error log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sqlplus error output to different error log file
# 1  
Old 02-11-2009
Bug sqlplus error output to different error log file

HELLO,

I am using such a command to write oracle sqlplus query result to text file:
sqlplus -S xxx/xxx@xxxxxxx @\tmp\2.sql>\tmp\123.txt
Is it possible to script that:
If command succesfull write in \tmp\log.txt:
timestamp and "succeded"
and create 123.txt with results
else
If error occured (ORA error, or OS error), write in \tmp\log.txt file
timestamp "failed" error code
(but don't write error in file 123.txt - dont create file 123.txt)

Many thanks,

Tomas
# 2  
Old 02-11-2009
Tomas,

Seems like you are asking for too much to write in a single command! I do not think it is possible to execute However, we can certainly write a shell script that satisfies your requirement, albeit with some modifications.

Code:
 
timestamp=`date '+%d%b%Y%H%M%S'`
sqlplus -S xxx/xxx@xxxxxxx @\tmp\2.sql > /tmp/result.txt
sqlplus_stat="$?"

if [[ ${sqlplus_stat} -eq 0 ]]; then
  echo "${timestamp} Successful" > /tmp/log.txt
  cp -p /tmp/result.txt /tmp/123.txt
else
  echo "${timestamp} Failure" > /tmp/log.txt
  cat /tmp/result.txt >> /tnp/log.txt
fi

HTH,Smilie

Regards,

Praveen
# 3  
Old 03-25-2009
I only think that will work if the input sql file exists. If it doesn't exist, the exist code sqlplus returns to the shell is 0.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies

2. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

3. Shell Programming and Scripting

Log sqlplus output from Shell

UNIX Gods, I'll be running this script from CRON. I need to log the status of each of the six sqlplus calls into a file when this job is kicked off. Any suggestions? Thanks in advance. #!/bin/ksh export USAGE="USAGE: `basename $0` -e <DBUSER> <DBPASSWD> <TNSNAME>" if ; then ... (2 Replies)
Discussion started by: WhoDatWhoDer
2 Replies

4. Shell Programming and Scripting

Format the output from sqlplus while writing to log file.

Hi I have developed bash script to connect to database and execute .sql files. I am logging some statements in to log file using echo. While logging I am adding the date in front of the log statements which makes sense. I am unable to add date in front of output from the sqlplus and sqlldr,... (8 Replies)
Discussion started by: murtymvvs
8 Replies

5. Shell Programming and Scripting

SQLPLUS error output....pls help...wasted all my day.

Code: print "$DB_CONNECT\n@$SQLDIR/SQLFILE.sql $INPUT" | sqlplus -s 2>> $LOGFILE | tee $IDW_HOME/data/supp/OUTPUTFILE1.dat | $PL_HOME/tabify_465.p > $IDW_HOME/data/supp/OUTPUTFILE2.txt 2>> $LOGFILE EXTRACT_RETURN_CODE=$? if then echo "EXTRACT or Tabify FALIED" >> $LOGFILE exit... (2 Replies)
Discussion started by: knarula
2 Replies

6. Shell Programming and Scripting

Appending error messages from log file next to the corresponding error record

Hi Everyone, I have an issue and trying to get a solution but was not succesful yet. Any help is greatly appreciated. I am using ksh to inoke sql loader to load data from txt file into two oracle tables based on the condition written in the control file. If an error occurs while loading into... (8 Replies)
Discussion started by: vpv0002
8 Replies

7. Shell Programming and Scripting

error running sqlplus from shell file

I am running a shell file following script on bash shell in solaris 10 ( echo abc@orcl echo abc echo "set feedback off" echo "truncate table SIndexDataTypeHst1_changes;" ) | sqlplus -s but getting the following error ERROR: ORA-01005: null password given; logon denied ... (3 Replies)
Discussion started by: mmunir
3 Replies

8. Shell Programming and Scripting

SQLPLUS error

I am running a script that invokes SQLPLUS. During the execution I get the following: SQL*Plus: Release 9.2.0.8.0 - Production on Mon Jun 11 16:12:50 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle9i Enterprise Edition Release 9.2.0.8.0 -... (3 Replies)
Discussion started by: ssmith001
3 Replies

9. UNIX for Dummies Questions & Answers

File Format issue: Output of sqlplus

Hi, I am using a query like below in my shell script : { { echo "set echo off" echo "set head off" echo "whenever sqlerror exit -1; select NUMBER ||','|| FNAME ||','|| LOC ||','|| ... (2 Replies)
Discussion started by: deepakgang
2 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