And I use:
!/bin/ksh
#
#-----------------------------------------------------------------------------------------------------------------
#
#
# ebs_drv_chk : This script checks the status of all drives on all media servers. The master server is
# considered to be a media server, so it will be included in the check. When a drive is
# detected as being down , we will attempt to bring the drive to an "up state". If after
# 3 attempts, it is still down, an error message wil be sent to the EBS adminsitrators and
# the operations groups so that a serviceman can be called in...
#
# Since we are using a TLD robotic device, we will also check to make sure that it is not
# in "manual mode" (AVR). AVR can occur at the startup of NetBackup but will clear as soon
# as Volume Manager has started it's daemons and gained control. However, in the course of
# normal operations one should not encounter AVR unless the robotic device is hung. We will
# check for AVR and will falg this as an error if it is still present after 5 minutes...
#
#-----------------------------------------------------------------------------------------------------------------
#
#
# Set script variables
#
EBSMAIL="/usr/local/bin/ebsmail.sh" # EBS common mail script
EBSNBDIR=/usr/openv/netbackup/bin # Set the name of the Netbackup command directory
EBSADMCMD=$EBSNBDIR/admincmd # Set the name of the Netbackup Administrator command directory
EBSVOLMGR=/usr/openv/volmgr/bin # Set the name of the Volume manager command directory
VMOPRCMD=$EBSVOLMGR/vmoprcmd # Set vmoprcmd cmommand variable
EBS_DIR=/usr/local/EBSDRIVES # Set name of drive directory
MSGHDR="$EBS_DIR/ebshdr" # Set name of message header file
MAILMSG="$EBS_DIR/mail.out" # Set name of merged mail file
EBSDRVLOG=$EBS_DR/EBSDRIVES/hist.log # Set name of temporary drive check fil
EBSDRVCHK=/tmp/EBS # Set name of temporary drive check file
EBSWORK=/tmp/ebswork # Set the name of the temporary work file
EBSDRIVE="fred" # Set initial value of drive name
EBSLEEP=900 # Set initial sleep time value
EBSLIB=TLD # Set Robotic type to TLD (others as ACS, TL8, Tl4, etc...)
EBSSERVERS=`$EBSADMCMD/bpstulist | awk '{print $3}' | sort -u`
EBSOPER=someone who cares # Set default e-mail recipients
#
#
#-----------------------------------------------------------------------------------------------------------------
#
# The following are the functions used by this script
#
#-----------------------------------------------------------------------------------------------------------------
#
function ebs_chk_down # Check if drive is down
{
$VMOPRCMD -h $EBSMEDIA -d ds | grep $EBSLIB | grep DOWN >/dev/null 2>&1 # See what drives are down
if [ $? -ne 1 ] # Are there any downed drives?
then # Yes,,,
$VMOPRCMD -d ds -h $EBSMEDIA | # Get the list of drives
tail +5 | # Remove the headers
grep $EBSLIB | # Retrieve only this library type
grep DOWN | # Select only the down'ed drives
awk '{print $1}'>$EBSWORK # Set the drive index(es)
cat $EBSWORK| # Let's see how many drives are down
while read EBSDRNDX # Scan through the list of downed drives
do
EBSDRIVE=`$VMOPRCMD -d ad -h $EBSMEDIA| # Now we will get the drive name
tail +5 | # Remove the headers
grep " $EBSDRNDX "| # Get drive name and it's info
awk '{print $2}'` # Set the Drive name for later usage
echo "`date` Drive $EBSDRIVE on $EBSMEDIA is in a DOWN state ">>$MAILMSG # This is the real drive name
echo "`date` Will attempt to place $EBSDRIVE on $EBSMEDIA in an UP state" >>$EBSDRVCHK$EBSMEDIA.$EBSDRNDX
echo "`date` Will attempt to place $EBSDRIVE on $EBSMEDIA in an UP state
">>$MAILMSG
done
return 4 # Set return code as downed drive(s)
fi
}
#
# This function will attempt to bring the drive to an up state
#
function ebs_up_drive # Bring down drive to up state
{
for EBSDRNDX in `$VMOPRCMD -d ds -h $EBSMEDIA | tail +5 | # Get the list of drives
grep $EBSLIB | grep DOWN |awk '{print $1}'`
do
$VMOPRCMD -up $EBSDRNDX -h $EBSMEDIA # Try to bring the drive up
# echo "Would bring drive up here"
EBSERCNT=`wc -l $EBSDRVCHK$EBSMEDIA.$EBSDRNDX |awk '{print $1}'` # Set the number of errors
echo " The error count for $EBSDRVCHK$EBSMEDIA.$EBSDRNDX is $EBSERCNT">>$MAILMSG
done
}
#
#
#
#function ebs_error_count # Check the number of errors
#{
# To be added at a leter time...
#}
#
#
# Clean up old Logs
for EBSMEDIA in $EBSSERVERS # Check all media servers
do
if [ -s $EBSDRVCHK.$EBSMEDIA ] # Are there any residual files?
then # Yes,,,
rm $EBSDRVCHK.$EBSMEDIA # Remove any residual files
fi
done
# Clean up done
#
while [ 1 == 1 ] # Setup infinite loop
do
echo "Subject: Inetrnal EBS - Downed Drive Report
">$MAILMSG # Setup message header
echo "The following drives are in a downed state
">>$MAILMSG
for EBSMEDIA in $EBSSERVERS # Check all the drives in all media servers
do
ebs_chk_down # Check if any drives are down
if [ "$?" -ne "0" ] # Is there a downed drive?
then # Yes,,,
ebs_up_drive # Bring any downed drive to the up state
EBSLEEP=30 # Set sleep time to 5 minutes
$EBSMAIL $MAILMSG $EBSOPER # Send the Down'ed drives message
# ebs_error_count # Check the number of errors
fi
done
if [ "$EBSLEEP" -ne "30" ] # Is there a downed drive?
then # No,,,
EBSLEEP=300 # Set wait time is 5 minutes
rm -f $EBSDRVCHK* # Remove any expired log files
fi
sleep $EBSLEEP # Wait until timer expires
EBSLEEP=900 # Set sleep time to default
rm $MAILMSG # Delete any message file
done