1、cat megacli.sh
#!/bin/bash
#--------------------------------------------------
#Created:2015-05-22
#Author:jimmygong
#Mail:jimmygong@taomee.com
#Function:
#Version:1.0
#--------------------------------------------------
function megacliaction ()
{
megacmd="/usr/local/sbin/MegaCli64"
if [[ -e $megacmd ]]
then
critical=$(sudo $megacmd -AdpAllInfo -aALL -NoLog|awk '/Critical Disks/ {print $4}')
failed=$(sudo $megacmd -AdpAllInfo -aALL -NoLog|awk '/Failed Disks/ {print $4}')
[[ -z $critical ]] || [[ -z $failed ]] && echo "Storage Capture Failure" && exit 0
[[ $critical -ne 0 ]] || [[ $failed -ne 0 ]] && echo "Storage Disk Failure" && exit 0
echo "Storage Disk Normal"
else
echo "MegaCli64 Problem"
exit 1
fi
}
megacliaction
exit 0
2、查看raid信息
cat megacli2.sh
#!/bin/bash
#--------------------------------------------------
#Created:2015-05-22
#Author:jimmygong
#Mail:jimmygong@taomee.com
#Function:
#Version:1.0
#--------------------------------------------------
function diskstatus ()
{
echo -e "===============Raid Information==============="
cmd="/usr/local/sbin/MegaCli64"
raid=`$cmd -cfgdsply -aALL|grep "RAID Level"|tail -1|awk -F: '{print $1" :"$2}'`
disknum=`$cmd -cfgdsply -aALL|grep "Number Of Drives"|awk -F: '{print $2}'`
onlinedisk=`$cmd -cfgdsply -aALL|grep -c "Online"`
faileddisk=`$cmd -AdpAllInfo -aALL -NoLog|awk '/Failed Disks/ {print $4}'`
criticaldisk=`$cmd -AdpAllInfo -aALL -NoLog|awk '/Critical Disks/ {print $4}'`
case "$raid" in
"RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0")
echo "Raid Level:1";;
"RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0")
echo "Raid Level:0";;
"RAID Level : Primary-5, Secondary-0, RAID Level Qualifier-3")
echo "Raid Level:5";;
"RAID Level : Primary-6, Secondary-0, RAID Level Qualifier-3")
echo "Raid Level:6";;
"RAID Level : Primary-1, Secondary-3, RAID Level Qualifier-0")
echo "Raid Level:10";;
esac
echo "Total Diak Number:$disknum"
echo "Online Disk Number:$onlinedisk"
echo "Failed Disk Number:$faileddisk"
echo "Critical Disk Number:$criticaldisk"
echo -e "===============Current Status================="
$cmd -PDList -aALL|grep "Firmware state"
}
diskstatus
exit 0
执行结果:
===============Raid Information===============
Raid Level:5
Total Diak Number:7
Online Disk Number:7
Failed Disk Number:0
Critical Disk Number:0
===============Current Status=================
Firmware state: Online
Firmware state: Online
Firmware state: Online
Firmware state: Online
Firmware state: Online
Firmware state: Online
Firmware state: Online
Firmware state: Hotspare
参考链接 :
MegaCli的相关shell脚本 :
https://blog.51cto.com/u_7938217/1653705