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