1. 程式人生 > >檢測raid類型和磁盤壞道腳本

檢測raid類型和磁盤壞道腳本

hostname inux tex img 磁盤信息 second har inf printf

#!/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

技術分享圖片

檢測raid類型和磁盤壞道腳本