Operating System - HP-UX
1753993 Members
7245 Online
108811 Solutions
New Discussion юеВ

Testing the exit code of fbackup in a script

 
Scott Hebl
Occasional Contributor

Testing the exit code of fbackup in a script

I have a scripting related question that hopefully someone can shine some light on...

I have a somewhat risky operation (resizing hashed files) that needs to be run once a week in the middle of the night. I only want the job to run if I can confirm that I got a good backup and there were no problems...

SO, what I would like to do is cron a script that checks the exit code of the fbackup job, and if it was 4 or less, then go ahead and do the file resizing... If the exit code from fbackup was 5 that means the backup had fatal errors, and in that case I wouldn't want to do the resize....

The logic seems simple, the only problem is that my scripting skills are pretty limited... Can anyway get me going in the right direction?

Thanks
4 REPLIES 4
Sachin Patel
Honored Contributor

Re: Testing the exit code of fbackup in a script

Hi Scoot,

Here is what you can do
set LOGFILE = /usr/adm/fbackupfiles/fbackup.log (you can set this file whereever you want)
set FBACKUP = /usr/sbin/fbackup
set GRAPH = /usr/adm/fbackupfiles/graphs/usr-usrlib (if you want to use graph file, else you can use i=include and e=exclusde )
set TEE = /bin/tee
set LEVEL = ?0? is you are doing level0 backup

#If you are not using graph file then you don?t need option g.
#If you are doing level0 backup everyday for say file system /usr then it should look like this
#( $FBACKUP ?0u ?i /usr ?f /dev/rmt/0m; echo; echo "fbackup Exit Status $status" ) |& $TEE -a $LOGFILE

( $FBACKUP -${LEVEL}ug $GRAPH -f $DEVICE; sleep 5;echo; echo "fbackup Exit Status $status" ) |& \ $TEE -a $LOGFILE
set RESULT = `tail -1 $LOGFILE | awk '{print $4}'`

if ( $RESULT == "0" ) then
echo "" >> $LOGFILE
echo "Successful Backup of $SYSTEM" >> $LOGFILE
#/bin/clear
echo ""
echo " *****************************"
echo " * *"
echo " * DONE *"
echo " * *"
echo " *****************************"
else
echo ? FAIL ?
endif

Sachin
Is photography a hobby or another way to spend $
Tom Danzig
Honored Contributor

Re: Testing the exit code of fbackup in a script

#!/usr/bin/sh

fbackup ...............

if [[ $? -le 4 ]] ; then
Backup OK. Commands to do whatever ...
else
Backup failed; Do whatever...
fi
Scott Hebl
Occasional Contributor

Re: Testing the exit code of fbackup in a script

THanks for the suggestions! I will give them a try.
Thierry Poels_1
Honored Contributor

Re: Testing the exit code of fbackup in a script

hi,

even if overall backup succeeded it might still be possible that the file you want to process was not successfully dumped!

Please note that Sachin's script is a C shell script and has to be executed by /usr/bin/csh.

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.