   |  | | PART II: - Beyond a basic Oracle EXP/IMP shell script: Error Handling & Exit | PART II: - Beyond a basic Oracle EXP/IMP shell script: Error Handling & Exit 2005-09-01 - By Radoulov, Dimitre
RE: PART II: - Beyond a basic Oracle EXP/IMP shell script: Error Handling & Exit Status?Try it like this:
=============================================================================== ======= export_simple_script_wrapper.sh: =============================================================================== =======
################### # ERROR HANDLING & RETURN CODES ################### export log_file="export_simple_script_wrapper.log" # RETURN CODE: Set initial Return Code - RC for this script. RC=1 echo 'RETURN CODE: Set initial Return Code - RC for this script.' >> $log_file 2>&1 echo $RC >> $log_file
cleanup() { echo cleaning up echo "RETURN CODE: $RC" }
trap 'cleanup; exit $?' EXIT
######################## # EXECUTE SCRIPT LOGIC: 1 ######################## #typeset -i RC=`/bin/sh /app/oracle/stagearea/export_simple_script.sh` /app/oracle/stagearea/export_simple_script.sh RC=$? if [[ $RC -ne 0 ]]; then exit else echo ' ' >> $log_file echo 'ORACLE EXPort SUCCEEDED!: '$RC >> $log_file 2>&1 echo $RC >> $log_file echo ' ' >> $log_file fi
# RETURN CODE: Show EXPort Return Code - RC: EXPort RETURN CODE. #RC=$? echo 'RETURN CODE: Show EXPort Return Code - RC: EXPort RETURN CODE.' >> $log _file 2>&1 echo $RC >> $log_file
=============================================================================== ======= export_simple_script.sh: =============================================================================== =======
######################## # EXECUTE SCRIPT LOGIC: 1 ########################
exp userid=test/test file=test.dmp log=test.log >> $log_file 2>&1 export RC=$?
# RETURN CODE: Set next Return Code - RC: ORACLE EXP RETURN CODE. #RC=$? echo 'RETURN CODE: Set next Return Code - RC: ORACLE EXP RETURN CODE.' >> $log _file 2>&1 echo $RC >> $log_file
if [[ $RC -eq 1 ]]; then echo ' ' >> $log_file echo 'ORACLE EXPort FAILED!: '$RC >> $log_file 2>&1 echo ' ' >> $log_file
elif [[ $RC -eq 0 ]]; then echo ' ' >> $log_file echo 'ORACLE EXPort SUCCEEDED!: '$RC >> $log_file 2>&1 echo ' ' >> $log_file
else echo ' ' >> $log_file echo 'ORACLE EXPort Utility STOPPED!: '$RC >> $log_file 2>&1 echo ' ' >> $log_file
fi
exit $RC
=============================================================================== =======
Output & logfile:
$ ./export_simple_script_wrapper.sh cleaning up RETURN CODE: 1
$ vi export_simple_script_wrapper.log "export_simple_script_wrapper.log" 19 lines, 538 characters RETURN CODE: Set initial Return Code - RC for this script. 1
Export: Release 9.0.1.5.0 - Production on Thu Sep 1 22:53:33 2005
(c) Copyright 2001 Oracle Corporation. All rights reserved.
EXP-00056: ORACLE error 1034 encountered ORA-01034 (See ORA-01034.ora-code.com): ORACLE not available ORA-27101 (See ORA-27101.ora-code.com): shared memory realm does not exist SVR4 Error: 2: No such file or directory EXP-00005: all allowable logon attempts failed EXP-00000: Export terminated unsuccessfully RETURN CODE: Set next Return Code - RC: ORACLE EXP RETURN CODE. 1
ORACLE EXPort FAILED!: 1
HTH Dimitre Radoulov
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>RE: PART II: - Beyond a basic Oracle EXP/IMP shell script: Error Handling & Exit Status?</TITLE> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2900.2722" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Try it like this:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>======================================================================== ==============</FONT></DIV> <DIV><FONT face=Arial size=2>export_simple_script_wrapper.sh:</FONT></DIV> <DIV><FONT face=Arial size=2>======================================================================== ==============</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>###################<BR># ERROR HANDLING & RETURN CODES<BR>###################<BR>export log_file="export_simple_script_wrapper.log"<BR># RETURN CODE: Set initial Return Code - RC for this script.<BR>RC=1<BR>echo 'RETURN CODE: Set initial Return Code - RC for this script.' >> $log_file 2>&1<BR>echo $RC >> $log_file</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>cleanup()<BR>{<BR> echo cleaning up<BR> echo "RETURN CODE: $RC"<BR>}</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>trap 'cleanup; exit $?' EXIT</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>########################<BR># EXECUTE SCRIPT LOGIC : 1<BR>########################<BR>#typeset -i RC=`/bin/sh /app/oracle/stagearea/export_simple_script.sh`<BR>/app/oracle/stagearea/export _simple_script.sh<BR>RC=$?<BR>if [[ $RC -ne 0 ]]; then<BR> exit<BR>else<BR> echo ' ' >> $log_file<BR> echo 'ORACLE EXPort SUCCEEDED!: '$RC >> $log_file 2>&1<BR> echo $RC >> $log_file<BR> echo ' ' >> $log_file<BR>fi</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2># RETURN CODE: Show EXPort Return Code - RC: EXPort RETURN CODE.<BR>#RC=$?<BR>echo 'RETURN CODE: Show EXPort Return Code - RC: EXPort RETURN CODE.' >> $log_file 2>&1<BR>echo $RC >> $log_file</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>======================================================================== ==============</FONT></DIV> <DIV><FONT face=Arial size=2>export_simple_script.sh:</FONT></DIV> <DIV><FONT face=Arial size=2>======================================================================== ==============</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>########################<BR># EXECUTE SCRIPT LOGIC : 1<BR>########################</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>exp userid=test/test file=test.dmp log=test.log >> $log_file 2>&1<BR>export RC=$?</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2># RETURN CODE: Set next Return Code - RC: ORACLE EXP RETURN CODE.<BR>#RC=$?<BR>echo 'RETURN CODE: Set next Return Code - RC: ORACLE EXP RETURN CODE.' >> $log_file 2>&1<BR>echo $RC >> $log_file</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>if [[ $RC -eq 1 ]]; then<BR> echo ' ' >> $log_file<BR> echo 'ORACLE EXPort FAILED!: '$RC >> $log_file 2>&1<BR> echo ' ' >> $log_file</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>elif [[ $RC -eq 0 ]]; then<BR> echo ' ' >> $log_file<BR> echo 'ORACLE EXPort SUCCEEDED!: '$RC >> $log_file 2>&1<BR> echo ' ' >> $log_file</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>else<BR> echo ' ' >> $log_file<BR> echo 'ORACLE EXPort Utility STOPPED!: '$RC >> $log_file 2>&1<BR> echo ' ' >> $log_file</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>fi</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>exit $RC</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>======================================================================== ==============</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Output & logfile:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>$ ./export_simple_script_wrapper.sh<BR>cleaning up<BR>RETURN CODE: 1</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>$ vi export_simple_script_wrapper.log <BR>"export_simple_script_wrapper.log" 19 lines, 538 characters <BR>RETURN CODE : Set initial Return Code - RC for this script.<BR>1</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>Export: Release 9.0.1.5.0 - Production on Thu Sep 1 22:53:33 2005</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>(c) Copyright 2001 Oracle Corporation. All rights reserved.</FONT></DIV> <DIV> </DIV><FONT face=Arial size=2> <DIV><BR>EXP-00056: ORACLE error 1034 encountered<BR>ORA-01034 (See ORA-01034.ora-code.com): ORACLE not available<BR>ORA-27101 (See ORA-27101.ora-code.com): shared memory realm does not exist<BR>SVR4 Error: 2: No such file or directory<BR>EXP-00005: all allowable logon attempts failed<BR>EXP-00000: Export terminated unsuccessfully<BR>RETURN CODE: Set next Return Code - RC: ORACLE EXP RETURN CODE.<BR>1</DIV> <DIV> </DIV> <DIV>ORACLE EXPort FAILED!: 1</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>HTH</FONT><BR>Dimitre Radoulov</DIV> <DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
|
|
 |