#! /bin/bash #****************************************************************************** #****************************************************************************** # # available_scratch_media # # This script can be used by an administrator as a convenient way to # list ALL NetBackup scratch volumes in the Media Manager volume database, and # report how many remaining scratch media remain in each robot. # The major benefit of this script is that it eliminates the need to track # information from multiple databases and do the correlation manually. # # This script can be used in a crontab entry to get periodic reports of # available media. # # ============================================================================= # ============================================================================= if [ "$1" = "-usage" ] ; then echo "usage: $0 " exit 0 fi if [ -f /usr/openv/netbackup/version ] ; then HARDWARE=`head -1 /usr/openv/netbackup/version | cut -f2 -d" "` else echo "/usr/openv/netbackup/version not found" exit 1 fi # Variables *** CHANGE THIS *** SOMEONE_WHO_CARES="someone@somewhere" # Commands today=`date +%m/%d/%y` VMQUERY=/usr/openv/volmgr/bin/vmquery VMPOOL=/usr/openv/volmgr/bin/vmpool BPMEDIALIST=/usr/openv/netbackup/bin/admincmd/bpmedialist TPCONFIG=/usr/openv/volmgr/bin/tpconfig # Temp Files VMQUERY_OUTPUT=/tmp/vmquery.out.$$ VMPOOL_OUTPUT=/tmp/vmpool_output.$$ BPMEDIALIST_OUTPUT=/tmp/bpmedialist_output.$$ ROBOT_Q=/tmp/robot_queue.$$ ROBOT_NUMBERS=/tmp/robot_numbers.$$ AVAILABLE_MEDIA_OUTPUT=/tmp/avail_media_output.$$ REPORT_OUTPUT=/tmp/avail_media_sorted_output.$$ /usr/openv/netbackup/bin/admincmd/bpauthorize -test_admin >/dev/null status=$? if [ ${status} -ne 0 ] ; then /bin/echo " You do not have the proper authorization to perform this task. Please resolve and try again." exit ${status} fi touch ${VMPOOL_OUTPUT} touch ${BPMEDIALIST_OUTPUT} if [ "Linux" = "`uname -s`" ] ; then TailOpt="-n" else TailOpt="" fi ${VMPOOL} -list_scratch 2>/dev/null | tail ${TailOpt} +3 | sort 1>${VMPOOL_OUTPUT} 2>/dev/null ${BPMEDIALIST} -mlist -l 1>${BPMEDIALIST_OUTPUT} 2>/dev/null cat ${VMPOOL_OUTPUT} | while read poolname poolhost pooluser poolgroup pooldesc do /bin/rm -rf ${VMQUERY_OUTPUT} /bin/rm -rf ${AVAILABLE_MEDIA_OUTPUT} touch ${VMQUERY_OUTPUT} ${VMQUERY} -pn ${poolname} -bx 2>/dev/null | tail ${TailOpt} +4 1>>${VMQUERY_OUTPUT} 2>/dev/null cat ${VMQUERY_OUTPUT} | while read vmediaid vmediatype vrobottype vrobotnum vrobotslot vside vvol vop vmnts vlmtdate vlmttime vasgndate vasgntime vpool do if [ "${vasgndate}" = "---" -a "${vasgntime}" = "---" ] ; then echo ${vrobotnum} >>${ROBOT_Q} fi done done # Use this command for all robots. ${TPCONFIG} -l | grep robot | cut -c11-12 > ${ROBOT_NUMBERS} # Use this command to only report robots with active scratch tapes. #sort -u ${ROBOT_Q} >> ${ROBOT_NUMBERS} cat ${ROBOT_NUMBERS} | while read robot do { SCRATCH_CNT=`egrep "^${robot}" ${ROBOT_Q} | wc -l` printf "Robot Nr. %6s has %9d scratch tapes remaining.\n" ${robot} ${SCRATCH_CNT} >> ${REPORT_OUTPUT} } done # mail the report to someone_who_cares cat ${REPORT_OUTPUT} | mailx -s "Scratch Pool Status for ${today}. " ${SOMEONE_WHO_CARES} #cat ${REPORT_OUTPUT} /bin/rm -rf ${REPORT_OUTPUT} ${AVAILABLE_MEDIA_OUTPUT} ${VMQUERY_OUTPUT} ${VMPOOL_OUTPUT} ${BPMEDIALIST_OUTPUT} ${ROBOT_Q} ${ROBOT_NUMBERS} ${REPORT_OUTPUT} #EOF