Return status...

Hello there!
Here is my problem. I hope I can get some help about it.
I need to know how can I get the return code of an application in the Unix shell script.

The script is like below:

PREVIOUS STATEMENT & VARIABLES

sqlplus scott/tiger @$sqldir/$sqlscript

NEXT STATEMENT (Like status=$?)

If for some reason sqlplus (Oracle client application for making a connection to Oracle or run a PL/SQL script against Oracle)
craps out, script will stop running, but, It does not return to the next statement after sqlplus... I've already tried "$?" to capture the return code but as I said the next statement after sqlplus never be reached....

I run the script using nohup on a AIX machine.

Thanks.
:confused:

"craps out" doesn't tell us very much.

If the program terminates, either because it explicitly decided to invoke the exit() system call or because of the default action of signal delivered to the process by the kernel, then control will pass to the next statement in your script and you may obtain the exit code.

On the other hand, if the process continues to run, then there is no exit code. A running process is a running process. You cannot get an exit code until a process exits.

Thanks for your answer.

I guess I need to put it this way. Assume I am running the Test.sh which is a Unix script and in the middle of Test.sh I call the sqlplus and the sqlplus successfully runs one script that has "exit" command which is the exit command for sqlplus and reaches the "exit" command and terminates the sqlplus. (I guess here is exit with return code zero otherwise I would see sqlplus prompt) but still doesn't get back to the Test.sh because my next statement after sqlplus is just a simple below code:
echo "Test.sh done!" > Test.sh.log
But this line never been executed.

I am a novice in Unix world. If I get disappointed, I get back to AS/400... I guess who cares...

Thanks a lot.
:confused:

Without seeing the script, its hard to see what is going wrong!!.. Can you do 2 things.

1 Post the script.
2 Post the output of the following command : ksh -x scriptname

where scriptname is your script!!

John

Try this:

RETURN=`sqlplus -s $USER <<END
select <column> from <table_name>;
quit
END`
if [ -z "$RETURN" ]; then
echo "Error - No rows returned "
exit 0
else
printf "Good return"
fi

Depends on what you're trying to do.

Hi,
Hrere is the script:
#########################################
#!/bin/sh

sqlplus $CONNECT_STRING @$SCRIPTDIR/$PLSQL_SCRPIT

status=$?
if [ $status -ne 0 ]
then
echo "Error in $SCRIPTDIR/$PLSQL_SCRPIT " > $LOGFILE
echo `date` >> $LOGFILE
exit 10010
else
echo "$PLSQL_SCRIPT finished successfully. " > $LOGFILE
echo `date` >> $LOGFILE
exit 0
fi
#########################################
After sqlplus execution it doesn't reach the status=$? statement.

Thanks a lot for your help.

I feel it is better to run child shell, so that once the child shell terminates, we can get the status of the shell which, in turn, returns the status of the command,....

Please repost if youneed any suggestions or research in UNIX, C,C++ and networking or kernel prog or embedded or system level....

Dear,
First of all, I don't know if you still need it. Anyway perhaps someone else can use it.
As far as I can see this is not really an unix problem.
Perhaps you should state in the beginning of your sql script
"WHENEVER OSERROR EXIT 1;
WHENEVER SQLERROR EXIT 1;"
and at the end of your sql script "EXIT 0;"

Greetings, P@rick