标签:hostname 位置 cto broadcast 技术 usr 类型 online raid
#!/bin/sh
#脚本功能:
#安装工具MegaCli64
#Host Information:主机名和ip地址
#Raid Information:raid信息和充电状态
#WARNING Information:MediaErrcount检测坏块和哪块盘
#Disk Information:磁盘信息
#上传MegaCli压缩包到opt目录下
Megdir=/opt/MegaRAID/MegaCli/
cd /opt
if [ ! -d $Megdir ];then
unzip MegaCLI.zip
cd 8.07.10_MegaCLI_Linux/Linux\ MegaCLI\ 8.07.10/
rpm -ivh MegaCli-8.07.10-1.noarch.rpm
cp /opt/MegaRAID/MegaCli/MegaCli* /usr/local/sbin
cp /opt/MegaRAID/MegaCli/MegaCli* /usr/sbin
echo "MegaCLI install sucess"
else
echo "MegaCLI already install"
Hostname=`/bin/hostname`
Hostip=`ifconfig | grep broadcast | awk "NR==1" | awk -F" " ‘{print $2}‘`
Battery=`MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL|grep "Charger Status"|awk -F: ‘{print $1" :"$2}‘`
raid=`MegaCli64 -cfgdsply -aALL|grep "RAID Level"|tail -1|awk -F: ‘{print $1" :"$2}‘`
Disknum=`MegaCli64 -cfgdsply -aALL|grep -c "Non Coerced Size"`
Onlinedisk=`MegaCli64 -cfgdsply -aALL | grep "Online" | wc -l | sed ‘s/ //‘`
Faileddisk=`MegaCli64 -AdpAllInfo -aALL | grep "Failed Disks"|awk -F‘ ‘ ‘{print $4}‘`
echo ""
echo "####################### Host Information #########################"
echo "HostName : $Hostname"
echo "HostIp : $Hostip"
echo ""
#raid信息
echo "####################### Raid Information ########################"
case "$raid"
in
"RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0") echo "Raid Level :Raid 1";;
"RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0") echo "Raid Level :Raid 0";;
"RAID Level : Primary-5, Secondary-0, RAID Level Qualifier-3") echo "Raid Level :Raid 5";;
"RAID Level : Primary-1, Secondary-3, RAID Level Qualifier-0") echo "Raid Level :Raid 10";;
esac
#充电状态
if [ -z "$Battery" ];then
echo "Battery :Null"
else
echo "$Battery"
fi
echo ""
echo "####################### WARNING Information ########################"
#预警的盘以及位置
CriticalDisk=`/usr/sbin/MegaCli64 -AdpAllInfo -aALL | grep "Critical Disks" | awk ‘{print $4}‘`
if [ $CriticalDisk -eq 0 ];then
echo "Critical Disks is:0"
else
CriDisk=`/usr/sbin/MegaCli64 -AdpAllInfo -aALL| grep -E ‘Predictive|Slot‘ | awk ‘{if(NR%3){printf$0":"}else{print $0}}‘|awk -F‘:‘ ‘{if($4!=0){print $2+1}}‘`
echo "WARNING Critical Disks In:$CriticalDisk"
echo "Sector In:$CriDisk"
fi
#MediaErrcount检测坏块和哪块盘
MediaErrcount=`/usr/sbin/MegaCli64 -pdlist -aALL | grep -E "Media Error" |awk -F’:’ -v errcount=0 ‘{errcount+=$2}END{print errcount}‘`
OtherErrcount=`/usr/sbin/MegaCli64 -pdlist -aALL | grep -E "Other Error" |awk -F’:’ -v errcount=0 ‘{errcount+=$2}END{print errcount}‘`
#坏盘的位置
if [[ $MediaErrcount==0||$OtherErrcount==0 ]];then
mDoD=`/usr/sbin/MegaCli64 -pdlist -aALL |grep -E "Media Error|Other Error|Slot" | awk ‘{if(NR%3){printf$0":"}else{print $0}}‘ | awk -F‘:‘ ‘{if($4!=0||$6!=0){print $2+1}}‘`
echo -e "Bad Block In:
$mDoD"
echo -e "CRITICAL:$MediaErrcount"
else
echo "mediaerr:0 and othererr:0"
fi
echo ""
echo "####################### Disk Information ########################"
echo "Total Disk Number:$Disknum"
echo "Online Disk Number:$Onlinedisk"
echo "Failed Disk Number:$Faileddisk"
echo ""
fi
标签:hostname 位置 cto broadcast 技术 usr 类型 online raid
原文地址:http://blog.51cto.com/chenhao6/2326028