#!/usr/bin/sh PATH=$PATH:/usr/local/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/volmgr/bin ADDR=someone.who.cares AT yourcompany DOT com TEMP1=/var/tmp/check-pending-1.$$ TEMP2=/var/tmp/check-pending-2.$$ TEMP3=/var/tmp/check-pending-3.$$ TRYLOGS=/usr/openv/netbackup/db/jobs/trylogs cleanup() { [ -f $TEMP1 ] && rm -f $TEMP1 [ -f $TEMP2 ] && rm -f $TEMP2 [ -f $TEMP3 ] && rm -f $TEMP3 } trap cleanup TERM EXIT # Get current time, figure out hi and low minutes to test against # (assumes this is run on 5 minute intervals) H=`date +'%H'` M=`date +'%M'` if [ $M -eq 0 ] then M=60 H=`expr $H - 1` [ $H -eq -1 ] && H=23 fi lo=`expr $M - 6` hi=`expr $M + 1` # Check for pending tape requests vmoprcmd -dp pr > $TEMP1 # PENDING REQUESTS # #ReqId User RecMID ExtMID Density Mode Time Barcode VolGroup #383399 003591 hcart Read 13:27 003591 OFFSITE_LTO # For each request, extract the time and barcode, then see if it # happened within the last window. Then check the active or suspended # restore jobs to see what media is required. If there are tapes that # are off-site, report which vault they live in along with any other # tapes required for the restore jobs. perl -ne 'if (m|(\d+:\d+\s+\d+)|) {print "$1\n";}' $TEMP1 | while read time media do h=`echo $time | awk -F: '{ print $1 }'` m=`echo $time | awk -F: '{ print $2 }'` if [ $m -eq 0 ] then m=60 h=`expr $h - 1` [ $h -eq -1 ] && h=23 fi if [ $h -eq $H ] then if [ $m -gt $lo -a $m -lt $hi ] then echo "Current restore jobs:" > $TEMP2 bpdbjobs | egrep -i 'restore.*(active|suspended)' | tee -a $TEMP2 | awk '{print $1}' | while read jobID do awk '/MEDIA_ID_NEEDED/ {print $NF, '$jobID'}' $TRYLOGS/${jobID}.t done | sort | uniq > $TEMP1 echo "" >> $TEMP2 echo "Tapes needed for restores:" >> $TEMP2 cat $TEMP1 | while read media jobID do if vmquery -m $media | grep -i 'robot type:.*none' > /dev/null 2>&1 then touch $TEMP3 vault=`vmquery -m $media | grep -i 'vault name:' | awk '{print $NF}'` echo $media \(job $jobID\) is off-site at $vault >> $TEMP2 echo Suspending job $jobID >> $TEMP2 bpdbjobs -suspend $jobID else echo $media \(job $jobID\) >> $TEMP2 fi done if [ -f $TEMP3 ] then mailx -r $ADDR -s "NetBackup vault tapes needed" $ADDR < $TEMP2 fi fi fi done