1823077 Members
3206 Online
109645 Solutions
New Discussion юеВ

Shell scripting

 
ramesh_6
Frequent Advisor

Shell scripting

Experts,
I dont know whether this is the right place i should put this RFH (Request For Help). I am executing a netbackup command which can throw three different error codes a 0,1 and 134. I have to handle these error codes in different manner. Let me put down the process how everything goes.

step -1 : script executes putting a flag called "backupstart" with time in a
text file..

Step-2: Execute the backup...list of file systems should be taken from another text file as input. basically we should be able to edit the text file at will for whatever file system we want to backup.

Step-3: Needs to be pretty smart in finding the exit code of step-3 and take corrective action

Following are the corrective actions

If ( "backupstart" flag exists && exit code == 134 ) Do nothing

else if ("backupstart" flag exists && exit code == 0) execute another script sample.sh
and remove the "backupstart" flag

else if (status == 1 && backupstart flag exists) e-mail/page support staff "someemail.email.com"

Experts first i dont know how to put a flag before starting the execution of the script as said in step-1.
I have the script for step-2. I dont know how to work handle the error codes for the and do something after that in Step-3.

I am attaching the script i have for step-2. If you can help me in getting step-1 and step-3 i would be grateful to you.
2 REPLIES 2
Steven E. Protter
Exalted Contributor

Re: Shell scripting

standard error trapping script logic.

/usr/openv/netbackup/backupscript
rc=$?

if [ $rc -eq 134 ] then
# take action based on code 134 email whatever
fi

# action
if [ $rc -eq 0 ] then
# take action based on code 134 email
sample.sh

fi

A little more elegant:

if [ $rc -nq 0 ] then
# action perhaps check the code and act.
else
#
sample.sh
fi


Thats how you trap and act on error codes.

I see no reason to make it really complex.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dave La Mar
Honored Contributor

Re: Shell scripting

Ramesh -
Below is a cut and paste from one of our netbackup scripts. It is pretty much what you are asking though our return code searches are different. Hope the lines "line up" on the paste to the reply.

Best of Luck.

Regards,

dl

# =================================================================================================
# Start the backup process.
# Create a touch file for verification of completed backup if successful.
# =================================================================================================
date > $ERROR_LOG1
$veritas_path/bpbackup -w -c $CLASS -s $SCHED -f $FILE_LIST_1
status=$?
if [ "$status" -eq 0 ]
then
echo "Backup results for $CLASS $FILE_LIST_1 return code $status" >> $RESULTS_FILE
touch $COMPLETED_FILE1
# =================================================================================================
# Call the call_umount script if all backups finished successfully.
# =================================================================================================

$CALL_UMOUNT
exit 0
fi

while [ "$status" -gt 0 ]
do
if [ "$status" -eq 84 -a "$count" -eq 0 ]
then
echo "Backup results for $CLASS $FILE_LIST_1 return code $status" >> $RESULTS_FILE
echo "Restarting this job at `date`" >> $RESULTS_FILE
$veritas_path/bpbackup -w -c $CLASS -s $SCHED -f $FILE_LIST_1
status=$?
let count="$count + 1"
elif [ "$status" -ne 84 -a "$status" -ne 0 ]
then
echo "Errors on backup for $CLASS return code $status" >> $ERROR_LOG1
echo "Contact Ron or Dave." >> $ERROR_LOG1
echo "Process affected is jdaprod backup." >> $ERROR_LOG1
echo "No completed flag will be created; umount will not occur." >> $ERROR_LOG1
$mail_path/mailx -s "Errors on backup of $CLASS Directory" $MAIL_LIST < $ERROR_LOG1
$VSE_NOTIFY
exit;
elif [ "$count" -eq 1 -a "status" -ne 0 ]
then
echo "Errors on backup for $CLASS return code $status" >> $ERROR_LOG1
echo "Contact Ron or Dave." >> $ERROR_LOG1
echo "Process affected is jdaprod backup." >> $ERROR_LOG1
echo "No completed flag will be created; umount will not occur." >> $ERROR_LOG1
$mail_path/mailx -s "Errors on backup of $CLASS Directory" $MAIL_LIST < $ERROR_LOG1
$VSE_NOTIFY
exit;
fi
done
"I'm not dumb. I just have a command of thoroughly useless information."