Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping Return Code from a Sybase Stored Proc 1

Status
Not open for further replies.

Autosys

Programmer
Jun 1, 2004
90
GB
Hi,

I've written a script which will execute a Sybase Stored Proc like this: exec $1 with $1 being the proc name.

I want my script to exit with a failure if the storedproc fails, i.e if the proc does not exist in the database or for any other data related failure.

I'm currently doing a if [ $? -eq 0 ] then SUCCESS else FAIL but this only traps the exit code from the isql program. Any failures that occured within the SQL isn't picked up on.

Could you please help! Thanks Stefan
 
So, you are executing a program inside of a program and the inside program is what you want to see the failure on? If the stored procedure is not successful, it should trigger an exit code of 1 for the "exec" command anyway, which they do by nature anyway. This should, in turn, trigger a failure in the script.
 
you may want to redirect the output of sql statement into a log file and then write some error trapping like the code below..

egrep -i "Error|Msg.*Level.*State|CT-LIBRARY error:" LOGS/sql.out >/dev/null
if [ $? -eq 0 ]
then
echo "#**********************DB-ERROR**********************#" >> ${FILENM}.out
cat ${1} >> ${FILENM}.out
echo "JOB ${FILENM} FAILED" >> ${FILENM}.out
exit 1
fi


Hope this Helps.

--TIA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top