|
Finding Bad Blocks Script |
Top Previous Next |
|
This is the source code for the FindBadBlocks.sh script shown in previous section. It has only been tested under Solaris 10, but serves as an example of what can be done to extend the functionality of the -bmsr command.
#!/bin/ksh # # Script Copyright 2008 SANtools (R) Inc. # By David A. Lethe david@santools.com # # This script parses bmsr output and provides list of devices and known bad blocks # It is not in public domain # Headed=0 function Header { if [ $Headed -eq 0 ] ; then printf "PhysicalDevPath Days:Hrs:Min Offset State\n" Headed=1 fi }
function OK { printf "%-20s - - OK\n" $LASTDEV }
TFILE=/tmp/smartscan.$$ /etc/smartmon-ux -bmsr > $TFILE LASTGOOD="" cat $TFILE | while read a b c d e f LASTDEV h do if [ "$a" = "Discovered" ] ; then if [ "$b" == "SEAGATE" ] ; then read a b ; read a b if [ "$a" != "-Background" ] ; then read x; read x; read x; read x; read x; read a b if [ "$a" == "Defect#" ] ; then DONE=0 ; COUNT=0 ; BAD=0 while read n pow blk REASON do if [ "$n" == $COUNT ] ; then BAD=`expr $BAD + 1` Header DAYS=`expr $pow / 1440` MIN=`expr $pow - $DAYS '*' 1440` HRS=`expr $MIN / 60` MIN=`expr $MIN - $HRS '*' 60` printf "%-20s%5d:%02d:%02d%8s " $LASTDEV $DAYS $HRS $MIN $blk CANDIDATE=`echo $REASON|grep WRITE` if [ "$CANDIDATE" != "" ] ; then echo $REASON else CANDIDATE=`echo $REASON|grep 'recovered via in` if [ "$CANDIDATE" != "" ] ; then REASON="Recovered via in-place rewrite" fi echo $REASON fi COUNT=`expr $COUNT + 1` else if [ "$BAD" -eq 0 ] ; then Header OK fi break fi done fi else Header OK fi fi fi done rm -f $TFILE |