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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SQLPLUS error output....pls help...wasted all my day.
# 1  
Old 08-25-2010
SQLPLUS error output....pls help...wasted all my day.

Code:

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 [ $EXTRACT_RETURN_CODE -ne 0 ]
	then	
	echo "EXTRACT or Tabify FALIED" >> $LOGFILE
	exit $EXTRACT_RETURN_CODE
	fi
....

In case i enter wrong user/pswd, i want to capture error msge there it self....

Now whats happening, If I enter wrong user/pswd, it doesnt exit there....populates my file OUTPUTFILE1 with error msg and then proceeds to tabify.pl...and status that i get in EXTRACT_RETURN_CODE is that of Tabify script......

Last edited by Scott; 08-25-2010 at 05:16 AM.. Reason: Please use code tags
# 2  
Old 08-25-2010
Quote:
Originally Posted by knarula
...
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 [ $EXTRACT_RETURN_CODE -ne 0 ]
    then    
    echo "EXTRACT or Tabify FALIED" >> $LOGFILE
    exit $EXTRACT_RETURN_CODE
    fi
....

In case i enter wrong user/pswd, i want to capture error msge there it self....

Now whats happening, If I enter wrong user/pswd, it doesnt exit there....populates my file OUTPUTFILE1 with error msg and then proceeds to tabify.pl...and status that i get in EXTRACT_RETURN_CODE is that of Tabify script......
I don't really know how your long pipeline of commands works, but I believe you are facing the problem because sqlplus allows 3 login attempts by default.

If your print command prints multiple lines, the first of which has incorrect login credentials, then sqlplus will read in the second line and assume that that it's your second attempt. And so on.

You may want to use the "-L" option of sqlplus to attempt the login only once. See if the password was correct. If it was, then go ahead with your script(s).

Here's a short shell script that tests this idea -

Code:
$
$
$ cat f0.sh
#!/usr/bin/bash
echo "select 1 x from dual;" | sqlplus -s -L $1/$2 1>/dev/null 2>&1
if [ "$?" -ne "0" ]
then
  echo "Incorrect password!"
  return
fi
echo "Correct password!"
sqlplus -s $1/$2 <<EOF
  select 0 x from dual;
  exit;
EOF
echo "End of script."
$
$
$
$ # Try the incorrect password first
$
$ . f0.sh test wrong_password
Incorrect password!
$
$ # And now the correct password
$
$ . f0.sh test test
Correct password!

         X
----------
         0

1 row selected.

End of script.
$
$

Type in "sqlplus --help" to see all the command-line options.

tyler_durden
# 3  
Old 08-25-2010
"set pipefail" is you are using bash. Also do "whenever sqlerror exit failure" in sqlplus before you connect.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Pls. help with vmstat output...

Hi, Users are reporting performance issue on my Sun Solaris 10 server. I am on the server. I don't see a issue or I might be looking at the wrong thing. Please help. I don't see anything on sar. it's all zero on that. Not sure why users are reporting high CPU and unresponsive at times. ... (1 Reply)
Discussion started by: samnyc
1 Replies

3. UNIX for Dummies Questions & Answers

netstat -an output, pls. explain..

Hi, I have old SCO O/S. System keeps crashing. I made lot of changes to kernel but so for nothing helped. I wrote a script which takes netstat -an output every one minute. I saw some thing right before the system crashed. Not sure if this means anything.. uname -a SCO_SV djx2 3.2... (2 Replies)
Discussion started by: samnyc
2 Replies

4. Solaris

sqlplus output from ksh.

Hi All, I have the below simple script. It runs just fine by itself when I manually invoke it. But once I put it in the crontab with entry: * * * * * /users/myuser/test.ksh >> /users/myuser/log/test.txt" It does NOT print the returned value ($REMAIN) from the DB!? The result in the... (3 Replies)
Discussion started by: steve701
3 Replies

5. Shell Programming and Scripting

store sqlplus output in variable

hi how can i store sqlplus output to a variable in sh script (not bash) Thanks MM (1 Reply)
Discussion started by: murtymvvs
1 Replies

6. Shell Programming and Scripting

Formatting Oracle sqlplus output

a job extracts orcle data into unix as flat file. a single record breaks into two record in unix flat file. This is the case only for 6 records out of 60 lack records. (its not single record in two line. but its single record into record. ie., \n come into picture) can you tell me what... (6 Replies)
Discussion started by: Gopal_Engg
6 Replies

7. Shell Programming and Scripting

output arguments from a sqlplus

Hi. I need to output a 4 queries result into another application using result=`sqlplus -s ${3}/${4}@${2} << EOF ... query1 query2 query3 query4 .... echo "$metrics1" and returning those individual values into another app. (query1 and 3compute one value, query 2 and 4 compute 4... (3 Replies)
Discussion started by: shell_zen
3 Replies

8. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: tomasba
2 Replies

9. UNIX for Dummies Questions & Answers

Getting output parameter in sqlplus

I need to get the output parameter from a stored procedure in sql plus using shell script. Can anyone help me please ... (1 Reply)
Discussion started by: risshanth
1 Replies
Login or Register to Ask a Question