Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Within the first afternoon I found 2 of the 3 needed solutions, and the 3rd came to me over the weekend!..."

Geography

Where in the world do Tek-Tips members come from?

Testing the status of an ORACLE call in a UNIX script

weberm (Programmer)
8 Oct 10 12:06
I have some inherited UNIX shell scripts that invoke sqlplus via a script called "qs" and then attempt to test their success or failure and behave accordingly but I'm having trouble finding researching "$?" online.  Here is such an example:

CODE

echo '--------------------------------------------------------------'
echo ' STEP01 -- PRODUCE THE UNRECONCILED ECOMMERCE REPORT          '
echo '--------------------------------------------------------------'
echo
$HOME/bin/qs "exec RCPI.ecommerce_reconciliation_rpt"

#Check if last command is successful.
if [ $? -ne 0 ]
then
echo "An error occurred while running the Unreconciled report. Exiting..."
exit 11
fi
Is the script testing a return code of some sort? If so, won't the only time it returns a bad value be if the invoked stored proc returns a non-zero value? ponder
razalas (Programmer)
8 Oct 10 12:14
$? is the shell variable that stores the last return code

A few others are:

CODE

echo "Command name:          " $0
echo "Process id:            " $$
echo "Background Process id: " $!
echo "Number of args:        " $#
echo "Return code:           " $?
echo "Args:                  " $*

man sh

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas

feherke (Programmer)
8 Oct 10 12:33
Hi

Razalas, based on the OP's code, he already knows how to use the $? variable.

weberm, note that qs is a client application, it not executes the received code. So it is not so sure it has to report the errors found by the server. ( I never used qs, this is based on other similar tools' behaviors. )

Personally I would try to detect the errors based on some specific words in the output :

CODE

$HOME/bin/qs "exec RCPI.ecommerce_reconciliation_rpt" 2>&1 | grep -qi 'error'

#Check if last command is successful.
if [ $? -ne 0 ]
then
  echo "An error occurred while running the Unreconciled report. Exiting..."
  exit 11
fi
Tested with GNU grep. Other grep implementations may not support -q ( --quiet ) and -i ( --ignore-case ) switches.

Feherke.
http://free.rootshell.be/~feherke/

weberm (Programmer)
8 Oct 10 13:31

Quote (razalas):

$? is the shell variable that stores the last return code
Thanks! I suspected question mark was a return code shell var but searching for "?" wasn't getting me anywhere.

Quote (feherke ):

weberm, note that qs is a client application, it not executes the received code. So it is not so sure it has to report the errors found by the server. ( I never used qs, this is based on other similar tools' behaviors. )
Personally I would try to detect the errors based on some specific words in the output
Feherke, qs is another script which invokes plsql:

CODE

echo "$*" |sqlplus -s scott/tiger
There are statements in the shell script which grep for "ORA-" and other key words, so I'm wondering why the original coder used $? in the first place since it appears to doing nothing. ponder
SamBones (Programmer)
8 Oct 10 14:17
Well, your "qs" script may not be returning the return code from sqlplus. You might try changing it to this...

CODE --> $HOME/bin/qs

echo "$*" |sqlplus -s scott/tiger
return $?
That way the script's return code is sqlplus' return code.


 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close