Skip to content

Instantly share code, notes, and snippets.

@prestelpirate
Last active December 7, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prestelpirate/9d1ba2d99fa80963ebc1c927b2dc0a71 to your computer and use it in GitHub Desktop.
Save prestelpirate/9d1ba2d99fa80963ebc1c927b2dc0a71 to your computer and use it in GitHub Desktop.
Used on hosts with Solaris Disksuite volume management. The script parses metastat output and checks the status of metadevices. Any errors are collated and a status report is emailed.
#!/bin/ksh
# See http://www.gaeltd.com/scripts-and-tools/ for more details
# 2005-01-10 Tom Kranz (tom@siliconbunny.com)
#
# Quickie script to catch Disksuite breakage
#
# We store a temp file in /tmp with our errors - once the script is complete, if
# that file has anything in it we know something has gone wrong - so we
# email it off
# Some vars
PATH=/usr/sbin:/usr/opt/SUNWmd/sbin:/usr/bin
# Odd path is easier than trying to work out where ODS tools have been
# hidden in this OE release :-)
HOSTNAME=`uname -n`
# Who do we want to know about breakage?
SYSADMINS=<email_address_here>
# Setup our temp file
OUTPUT=/tmp/ods_breakage.txt
# We don't want any old rubbish lying around
if [ -f $OUTPUT ]
then
rm $OUTPUT
fi
# Let's check to see if we actually have ODS, shall we?
if [ -z "`pkginfo | grep SUNWmdg`" ]
then
# If we silently bail, we can just roll this out across an
# estate as part of a standard toolkit
# Easier to support a common toolset installed on all machines
# than lots of local machine customisations
exit 1
fi
# Get metastat to list our mirrors
MIRRORS=`metastat | grep Mirror | cut -d: -f1`
# Cycle through the mirrors, looking for breakage
# Feel free to add extra if loops looking for specific issues
for MIRROR in $MIRRORS
do
if [ "`metastat $MIRROR | grep \"Needs maintenance\"`" != "" ]
then
echo "" >> $OUTPUT
echo "WARNING:" >> $OUTPUT
echo " Host $HOSTNAME reports that mirror $MIRROR needs maintenance!" >> $OUTPUT
echo "" >> $OUTPUT
elif [ "`metastat $MIRROR | grep \"Broken\"`" != "" ]
then
echo "" >> $OUTPUT
echo "WARNING:" >> $OUTPUT
echo " Host $HOSTNAME reports that mirror $MIRROR is *BROKEN*!" >> $OUTPUT
echo "" >> $OUTPUT
fi
done
# Now we need to check our output. If there's something there, we should email
# it off to concerned parties
if [ -f $OUTPUT ]
then
cat $OUTPUT | mailx -s "$HOSTNAME reports Disksuite anomalies!" $SYSADMINS
fi
# And we're done, except for the crying about dataloss, bad backups, etc. etc.
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment