File: //usr/local/sbin/Mega_Discover.sh
#!/bin/bash
Parameter=$1;
if [ $Parameter = "Discover" ]
then
#########################################################################
# Discover Physical DiskArrays #
#########################################################################
##Select the compatible megacli command
if [[ $(which MegaCli 1> /dev/null 2>&1 || echo $?) > 0 ]]
then
RAIDCOM="megacli"
else
RAIDCOM="MegaCli"
fi
DeviceNO=$(sudo $RAIDCOM -PDList -aALL|grep 'Enclosure Device ID'|wc -l);
deviceid=$(sudo $RAIDCOM -PdList -aALL | egrep -i "Slot|Device ID" | perl -pe 's/^(Enclosure Device ID|Slot Number): (\d+)\s$/$2\t/' | perl -pe 's/DeviceId: //')
DeviceID="{\"data\":[";
count=1;
while read ID;
do
id=$(echo $ID|awk '{print $5}');
DeviceID+="{\"{#ARRAY}\":\"$id\"}"
if (( $count < $DeviceNO ))
then
DeviceID+=",";
fi
count=$((count+1));
done <<< "${deviceid}"
DeviceID+="]}";
echo $DeviceID
exit;
fi ##/end of if Discover
#########################################################################
# Checking Hard Disk Health #
#########################################################################
if [[ $(sudo smartctl -d sat+megaraid,$Parameter -a /dev/sda|grep 'overall-health'| perl -pe 's/SMART overall-health self-assessment test result: //'|wc -l) == 0 ]]
then
HDDSTATUS=$(sudo smartctl -d megaraid,$Parameter -a /dev/sda|grep 'SMART Health Status'| perl -pe 's/SMART Health Status: //')
if [[ $HDDSTATUS == "OK" ]]
then
echo "1";
exit
else
echo "0";
exit
fi
else
HDDSTATUS=$(sudo smartctl -d sat+megaraid,$Parameter -a /dev/sda|grep 'overall-health'| perl -pe 's/SMART overall-health self-assessment test result: //')
if [[ "$HDDSTATUS" == "PASSED" ]]
then
echo "1";
exit
else
echo "0";
exit
fi
fi