PDA

View Full Version : scripting help


fildien
07-24-2008, 12:13 PM
I need to capture the exit code of the actual RMAN part of this script and not the other stuff. I know the answer is staring me in the face but I can't think of a simple way to do this without evaluating the exit of each step and dumping them to a file and the parsing the file. Seems bulky, there has to be an easier way, please help if you can.

I always get a fricking exit code of 0 no matter what I do.


#!/usr/bin/ksh
# 07-23-08 created
# 07-24-08 removed mailx line
set -x
export ORACLE_HOME=/u01/app/oracle/product/9.2.0.8
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=kprd
export LD_LIBRARY_PATH=/opt/CA/SharedComponents/JRE/1.4.2/lib:/u01/app/oracle/product/9.2.0.8/lib:/u01/app/oracle/product/9.2.0.8/jd
bc/lib
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=kprd
export PATH=/usr/bin:/usr/local/bin:/usr/bin/sh:/etc:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X11:/sbin:.:/u01/app/oracle/produc
t/9.2.0.8/bin:/u01/app/oracle/scripts
export CLASSPATH=/opt/CA/SharedComponents/JRE/1.4.2/lib/tools.jar:/u01/app/oracle/product/9.2.0.8/jdbc/lib/classes12.zip
TimeStamp=`date +%Y%m%d_%H%M%S`
export LOG=/backup1/rman_bkp_logs/kprd/${ORACLE_SID}_archive_log-${TimeStamp}.log
echo "Starting Time: `date`" > ${LOG}
/u01/app/oracle/product/9.2.0.8/bin/rman target / catalog rman/blahblahblah@rman1 <<! | tee -a ${LOG}
set echo on;
change archivelog all validate;
resync catalog;
run {
allocate channel t1 device type sbt format 'kprd_arch_%u_%p_%c'
parms='SBT_LIBRARY=/opt/CA/BABoraagt/libobk64.so' ;
BACKUP ARCHIVELOG ALL;
DELETE NOPROMPT ARCHIVELOG ALL BACKED UP 3 TIMES TO DEVICE TYPE 'SBT_TAPE';
}
exit 3

Sixee
07-24-2008, 02:16 PM
Load *.*,8,1 ?

Sorry I couldn't resist....

Palarran
07-24-2008, 03:12 PM
Can't you just assign it to a variable and then do something with it later in the script? Something like this:

{/u01/app/oracle/product/9.2.0.8/bin/rman target / catalog rman/blahblahblah@rman1; return_value=$?;} <<! | tee -a ${LOG}
...
exit $return_value # (or whatever else you want to do with the return value)


What does the "<<!" do? I don't think I've seen that before.

Malse
07-24-2008, 03:50 PM
You're getting a succesful exit (0) because of tee. If you don't need to watch STDOUT inline just send the whole thing to a log.



exec > $LOG 2>&1
echo "Starting Time: `date`
/u01/app/oracle/product/9.2.0.8/bin/rman target / catalog rman/blahblahblah@rman1 <<ENDRMAN
RMAN LANGUAGE HURT BRAIN ERROR 9040 FORMAT DIR DERKA DERKA
ENDMAN
rman_exit=$?

fildien
07-24-2008, 08:50 PM
You are correct malse it was the tee. I will post how I fixed it tommorow since I'm on iPhone but basically I dropped the tee and put a wrapper around the script, redirected output to another and used another script to capture the output before the pipe. Sounds wordy but it worked. The problem is I call this script from another product, it has to log in with the right variables and thee are three db instances on this node so bleh.

fildien
07-24-2008, 09:01 PM
to answer tal the !<< is telling the script to read the standard in or the meat of the rman job that follows.

fildien
07-25-2008, 08:39 AM
Here is how I fixed it. there is most likely an easier way but I do love the magic.ksh script :D So basically call script, file created to keep exit code at end of script look at that file and exit with that code. Easy peasy my brain was hurting yesterday afternoon I just couldn't figure out what the issue was until the tee command jumped out at me and I was like "DOH" dumbass :( Thanks for the input guys this was fun, I prefer Malse's RMAN script much more!

script #1

#!/usr/bin/ksh
# 07-23-08 created
# 07-24-08 removed mailx line
# 07-24-08 wrapped the script using magic.ksh and redirected output to Annette's location
set -x
jobStatFile="/usr/Backup/data/wigp_full"
TimeStamp=`date +%Y%m%d_%H%M%S`
export LOG=/backup1/rman_bkp_logs/wigp/wigp_HOTO-${TimeStamp}.log
echo "Starting Time: `date`" > ${LOG}

/usr/Backup/jobscripts/DBA1/magic.ksh $jobStatFile /u01/app/oracle/scripts/wigp_rman_tape_full_bkp.ksh >> ${LOG}

status=`more $jobStatFile`
#rm $jobStatFile
echo $status
exit $status


script #2 (magic.ksh)


filename=$1
shift
"$@"
echo $? 2>&1 > $filename

script #3 (original rman script with tee command removed)