Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drive watch script 2

Status
Not open for further replies.

syjl

Technical User
Jan 17, 2001
102
0
0
US
I have a unix master and win2k media servers. Not being a scripting guru I was wondering how I can make the script below work for me. Any ideas??




#!/bin/ksh
# Check Drives on Master Server, if down, bring drive up.
# Send an email to some one who cares.
# 04/08/02
#
#------------------------------------------------------------------
#BEGIN SCRIPT DRIVEWATCH
#!/usr/bin/ksh
#----------------------------------------------------------------------
# Keith G. Deems
# Check drives, bring drive up if down, email Staff
# If drives are up, do not create a report, runs from cron
#----------------------------------------------------------------------
# Add interested parties below:
someone_who_cares=jl1@ci.henderson.nv.us
/usr/openv/volmgr/bin/vmoprcmd -d ds | grep "DOWN-TLD" 2>&1
if [ $? -ne 1 ];then
echo " "
echo " "
rm /tmp/kgd/drivelog
/usr/bin/date >> /tmp/drivelog

echo "Please check DLT drives on MASTER:

`/usr/openv/volmgr/bin/vmoprcmd -d ds`

I will now attempt to place drive(s) in UP status" >> /tmp/drivelog
echo "" >> /tmp/drivelog
# for i in `/usr/openv/volmgr/bin/vmoprcmd -d ds | tail +5 | grep "DOWN"|awk '{print $1}'`
# do
# /usr/openv/volmgr/bin/vmoprcmd -up $i
# done
#/usr/openv/volmgr/bin/vmoprcmd -d ds >> /tmp/drivelog
cat /tmp/drivelog | /usr/bin/mail -s "Drive(s) on Veritas are DOWN" $someone_who_cares
fi

 
I use ...

#!/bin/ksh
#
#
###############################################################################
#
# Name: Check_for_downed_drives.ksh
# Purpose: This script checks the status of all tape drives and filters
# for any that may be in a down state.
#
# Modified by: Steve Staves
# Date Created: July 3rd, 2003
#
###############################################################################
#
# Set up variables

MASTER=<Your Master>
BPDIR=<Your Install Location>/netbackup/bin/admincmd
VMDIR=<Your Install Location>/volmgr/bin
TMPF=<A Location for the results>/results.txt
SERVERLIST='server1 server2 server3 server4 etc'

##################################################################
#
# Initialize Log File(s)

rm $TMPF

##################################################################
#
# Main body of Script

#Create report header
echo &quot;Single Tape Drive Servers&quot; >> $TMPF
echo &quot;------------------------------------------------------------------------------------------------&quot; >> $TMPF

for SERVER in $SERVERLIST; do
TEST=$($VMDIR/vmoprcmd -h $SERVER -d ds |grep -i -e down -e avr -e tld |awk '{print $3}')
if [ &quot;$TEST&quot; = &quot;DOWN&quot; ]
then
echo $SERVER &quot;has a drive that is down.&quot; >> $TMPF
elif [ &quot;$TEST&quot; = &quot;DOWN-TLD&quot; ]
then
echo $SERVER &quot;has a drive that is down.&quot; >> $TMPF
elif [ &quot;$TEST&quot; = &quot;AVR&quot; ]
then
elif [ &quot;$TEST&quot; = &quot;TLD&quot; ]
then
else
echo &quot;The NetBackup services on &quot;$SERVER &quot;are not running.&quot; >> $TMPF
fi
done
 
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 &quot;up state&quot;. 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 &quot;manual mode&quot; (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=&quot;/usr/local/bin/ebsmail.sh&quot; # 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=&quot;$EBS_DIR/ebshdr&quot; # Set name of message header file
MAILMSG=&quot;$EBS_DIR/mail.out&quot; # 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=&quot;fred&quot; # 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 &quot; $EBSDRNDX &quot;| # Get drive name and it's info
awk '{print $2}'` # Set the Drive name for later usage
echo &quot;`date` Drive $EBSDRIVE on $EBSMEDIA is in a DOWN state &quot;>>$MAILMSG # This is the real drive name
echo &quot;`date` Will attempt to place $EBSDRIVE on $EBSMEDIA in an UP state&quot; >>$EBSDRVCHK$EBSMEDIA.$EBSDRNDX
echo &quot;`date` Will attempt to place $EBSDRIVE on $EBSMEDIA in an UP state

&quot;>>$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 &quot;Would bring drive up here&quot;
EBSERCNT=`wc -l $EBSDRVCHK$EBSMEDIA.$EBSDRNDX |awk '{print $1}'` # Set the number of errors
echo &quot; The error count for $EBSDRVCHK$EBSMEDIA.$EBSDRNDX is $EBSERCNT&quot;>>$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 &quot;Subject: Inetrnal EBS - Downed Drive Report

&quot;>$MAILMSG # Setup message header
echo &quot;The following drives are in a downed state

&quot;>>$MAILMSG
for EBSMEDIA in $EBSSERVERS # Check all the drives in all media servers
do
ebs_chk_down # Check if any drives are down
if [ &quot;$?&quot; -ne &quot;0&quot; ] # 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 [ &quot;$EBSLEEP&quot; -ne &quot;30&quot; ] # 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
 
Phantom and BSWIP - Great posts - I can definitely use both those scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top