本节分享的这个shell脚本,用于自动检查服务器RAID信息。
代码:
#!/bin/sh
Hostname=`/bin/hostname`
Hostip=`awk -F= ‘/IPADDR/ {print $2}’ /etc/sysconfig/network-scripts/ifcfg-eth0`
Battery=`/opt/MegaCli -AdpBbuCmd -GetBbuStatus -aALL|grep “Charger Status”|awk -F: ‘{print $1″ :”$2}’`
raid=`/opt/MegaCli -cfgdsply -aALL|grep “RAID Level”|tail -1|awk -F: ‘{print $1″ :”$2}’`
Disknum=`/opt/MegaCli -cfgdsply -aALL|grep -c “Non Coerced Size”`
Onlinedisk=`/opt/MegaCli -cfgdsply -aALL | grep “Online” | wc -l | sed ‘s/ //’`
Faileddisk=`/opt/MegaCli -AdpAllInfo -aALL | grep “Failed Disks”|awk -F’ ‘ ‘{print $4}’`
echo “####### Host Information ######”
echo “HostName : $Hostname”
echo “HostIp : $Hostip”
echo “”
echo “##### Raid Information #####”
#echo “$Raidmode”
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 “Total Diak Number:$Disknum”
echo “Online Disk Number:$Onlinedisk”
echo “Failed Disk Number:$Faileddisk”
echo “”
MegaCli常用参数组合介绍:
磁带状态的变化,从拔盘到插盘的过程:
附,MegaCli工具的下载地址:
http://gcolpart.evolix.net/debian/misc/dell/MegaCli-1.01.24-0.i386.rpm
MegaCli工具的安装命令: