[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Port BB ext script to Hobbit



Hey guys,

Just wondering what is required to port a BB ext script from somewhere like Deadcat over to the hobbitclient ? I've had a poke and it looks as it the hobbit client sets all of the old $BB variables so the script should be fine but Im still having troubles cos I a script newb :)

This raid monitor script is the only one I managed to get working on one of the boxes here so I'd prefer to stick with it. As far as I know the script should be fine although the line where it execs bbedf.sh obviously wont work so I'm assuming this is why the hobbitlaunch.cfg sets the ENVFILE ?

Script is attached, if anyone could have a look and let me know whats up it would be GREATLY appreciated

Cheers

Allan

#!/bin/sh

################################ bb-mdstat.sh ################################
# This script was based on bb-raid.sh, it worked for me, but I only have     #
# a single raid5 array, so your mileage may vary. Apparently the             #
# /proc/mdstat file format changed from Linux 2.0 to 2.2 to 2.4, this script #
# works on Linux 2.4.x, and may work on other versions with the appropriate  #
# patches.								     #
#
# 03/10/2003                                                                  #
# Version 0.4 - Automatically detect number of raid devices. 
#									     #
# 25/09/2003                                                                  #
# Version 0.3 - Set to support more than four raid devices. 
#									     #
# 16/09/2001                                                                 #
# Version 0.2 - Significant bug fix for non-green detection. Added resync    #
#		detection to change to yellow. Various other minor cosmetic  #
#		bug fixes						     #
#                                                                            #
# 16/06/2001                                                                 #
# Version 0.1 - Initial write, so far it is confirmed to be green when       #
#               everything is OK, no other testing has been done!            #
##############################################################################

BBPROG=bb-mdstat.sh; export BBPROG

#
TEST="raid"
RAID_DEVICES=`df -k | grep ^/dev/md | wc -l`

if test "$BBHOME" = ""
then
	echo "BBHOME is not set... exiting"
	exit 1
fi

if test ! "$BBTMP"                      # GET DEFINITIONS IF NEEDED
then
	 # echo "*** LOADING BBDEF ***"
        . $BBHOME/etc/bbdef.sh          # INCLUDE STANDARD DEFINITIONS
fi

#
# NOW COLLECT SOME DATA

# md: syncing RAID array
# md: updating
# md: removing former faulty
# md: active

i=0
while [ "$i" -le "$RAID_DEVICES" ]
do
	store=0
	rm -f $BBTMP/RAID$i.$$
	cat /proc/mdstat | 
	while read line
	do
		echo $line | $GREP -q ^md
		if [ $? -eq 0 ]
		then
			echo $line | $GREP -q "^md${i} :"
			if [ $? -eq 0 ]
			then
				store=1
			else
				store=0
			fi
		fi
		if [ "$store" -eq 1 ]
		then
			echo $line >> $BBTMP/RAID$i.$$
		fi
	done
	i=`expr $i + 1`
done

i=0
while [ "$i" -le "$RAID_DEVICES" ]
do
	if test -r $BBTMP/RAID$i.$$
	then
		MD1="`$GREP / $BBTMP/RAID$i.$$|$AWK -F/ '{print $1}'|$HEAD -1|$TAIL -c2`"
		MD2="`$GREP / $BBTMP/RAID$i.$$|$AWK -F/ '{print $2}'|$HEAD -c1`"
		if test $MD1 -eq $MD2
		then
			STATUS="`$CAT $BBTMP/RAID$i.$$|$GREP "md$i"|$AWK '{print $3}'`"
			case $STATUS in
				updating) COLOR="yellow";;
				active)	COLOR="green"; TMPLINE="Status OK";;
			    	*) COLOR="red";;
			esac
		else
			COLOR="red"
			TMPLINE="Disk Failed"
		fi
		# Now check for resync RAID device
		RESYNC=`$HEAD -3 $BBTMP/RAID$i.$$| $TAIL -1 | $AWK '{print $2}'`
		if [ "$RESYNC" == "resync" ]
		then
			if [ ! "$COLOR" == "red" ]
			then
				COLOR="yellow"
				TMPLINE="resync in progress"
			fi
		fi
		echo "&${COLOR} md${i} $TMPLINE" > $BBTMP/RAID$i.out
	fi
	i=`expr $i + 1`
done

$GREP -q ^\&red $BBTMP/RAID*.out
if [ $? -eq 0 ]
then
	COLOR="red"
else
	$GREP -q ^\&yellow $BBTMP/RAID*.out
	if [ $? -eq 0 ]
	then
		COLOR="yellow"
	else
		$GREP -q ^\&green $BBTMP/RAID*.out
		if [ $? -eq 0 ]
		then
			COLOR="green"
		else
			COLOR="clear"
		fi
	fi
fi

RED=`grep -h ^\&red $BBTMP/RAID*.out`
YELLOW=`grep -h ^\&yellow $BBTMP/RAID*.out`
if [ -z "$RED" -a -z "$YELLOW" ]
then
	TMPLINE="ALL devices OK"
else
	TMPLINE="$RED $YELLOW"
fi

LINE="status $MACHINE.$TEST $COLOR `date` RAID $TMPLINE

"
i=0
while [ "$i" -le "$RAID_DEVICES" ]
do
   if [ -f $BBTMP/RAID0.out ]
   then
   	LINE="$LINE
   `cat $BBTMP/RAID$i.out`"
   fi
   i=`expr $i + 1`
done

LINE="$LINE

============================ /proc/mdstat ===========================

`cat /proc/mdstat`"

$RM -f $BBTMP/RAID*

$BB $BBDISP "$LINE"			# SEND TO BBDISPLAY