#!/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 ];thenunzip MegaCLI.zip cd 8.07.10_MegaCLI_Linux/Linux\ MegaCLI\ 8.07.10/rpm -ivh MegaCli-8.07.10-1.noarch.rpmcp /opt/MegaRAID/MegaCli/MegaCli* /usr/local/sbincp /opt/MegaRAID/MegaCli/MegaCli* /usr/sbinecho "MegaCLI install sucess"
elseecho "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" ];thenecho "Battery :Null"elseecho "$Battery"fiecho ""echo "####################### WARNING Information ########################"#预警的盘以及位置CriticalDisk=`/usr/sbin/MegaCli64 -AdpAllInfo -aALL | grep "Critical Disks" | awk '{print $4}'`if [ $CriticalDisk -eq 0 ];thenecho "Critical Disks is:0"elseCriDisk=`/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 ]];thenmDoD=`/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"elseecho "mediaerr:0 and othererr:0"fiecho ""echo "####################### Disk Information ########################"echo "Total Disk Number:$Disknum"echo "Online Disk Number:$Onlinedisk"echo "Failed Disk Number:$Faileddisk"echo ""
fi