LSI HBA卡下硬盘物理槽位和OS盘符对应脚本

2023-03-19  本文已影响0人  小御茶

有个大客户需要一个脚本可以打印出当前服务器上在位的硬盘OS下的硬盘盘符和服务器物理硬盘槽位号的对应关系,由于涉及HBA卡,所以无法实现一个通用的,只能是适用于这个配置的。经过验证在掉一个盘的情况下,其它硬盘的盘符不会发生漂移,掉盘多个的情况下会发生漂移,由于客户的使用场景一般掉盘一个就会预警了,所以这个需求还是有实现价值的。由于服务器上的是LSI的HBA卡,经过验证,盘符分配没有规律可循,只能记下满配时的盘符关系,用来检索输出。
思路就是先生成一个正确的物理槽位-盘符-阵列卡下槽位的对应关系,然后用阵列卡的工具去获取当前阵列卡下在位的硬盘槽位号,根据槽位号去获取正确的物理槽位,然后序列号和model根据盘符用smartctl命令获取
最终实现效果如下


slot.png
#!/bin/bash
function touch_physical_hba_os(){
b=`/opt/MegaRAID/storcli/storcli64 /c1 show | grep SATA | awk '{print $1}' | cut -d ':' -f 1 | uniq`
c=`/opt/MegaRAID/storcli/storcli64 /c0 show | grep SATA | awk '{print $1}' | cut -d ':' -f 1 | uniq | sed -n '1p'`
a=`/opt/MegaRAID/storcli/storcli64 /c0 show | grep SATA | awk '{print $1}' | cut -d ':' -f 1 | uniq | sed -n '2p'`

for((i=0;i<=55;i++));do
    if [[ $i -lt 28 ]];then
        echo N$(($i+1)),Front$i,$a:$i >> ph.csv
    else
        echo N$(($i+1)),Front$i,$b:$(($i-28)) >> ph.csv
    fi
done
for((i=1;i<=4;i++));do
    echo N$(($i+56)),Rear$i,$c:$(($i+11)) >> ph.csv
done
echo -e "N61,Rear7,$c:8\nN62,Rear8,$c:9" >> ph.csv
m=1
for i in sdg sdh sdi sdj sdk sdl sdm sdn sdo sdp sdq sdar sds sdt sdu sdv sdw sdx sdy sdz sdaa sdab sdac sdad sdae sdaf sdag sdah sdai sdaj sdak sdal sdam sdan sdao sdap sdaq sdar sdas sdat sdau sdav sdaw sdax sday sdaz sdba sdbb sdbc sdbd sdbe sdbf sdbg sdbh sdbi sdbj sdc sdd sde sdf sda sdb;do
    echo N$m,$i >> os.csv
    let m++
done

}
function check_present(){

for slot in /c0/e$c/s{12..15} /c0/e$a/s{0..27} /c1/e$b/s{0..27}; do /opt/MegaRAID/storcli/storcli64 ${slot} show J|jq -r '.Controllers[0]."Response Data"."Drive Information"[0]."EID:Slt"'; done >> present.txt
for slot in /c0/e$c/s{8..9}; do /opt/MegaRAID/storcli/storcli64 ${slot} show J|jq -r '.Controllers[0]."Response Data"."Drive Information"[0]."EID:Slt"'; done >> present.txt

t=`date +%Y-%m-%d-%H:%M:%S`
touch result-$t.txt
echo "Slot   :  OsName  :  diskserial  :  diskmodel" >> result-$t.txt
}
function output(){
while read LINE
do
        {
        [[ "$LINE" == "" ]] && continue
        p=`echo $LINE | awk -F ',' '{print $3}'`
        ps=`cat ph.csv | grep -iw $p | awk -F ',' '{print $2}'`
        n=`cat ph.csv | grep -iw  $p | awk -F ',' '{print $1}'`
        if [[ `cat present.txt | grep -w $p | wc -l` == 1 ]];then
        os=`cat os.csv | grep -iw $n | awk -F ',' '{print $2}'`
                diskmodel=`smartctl /dev/$os -a | grep -i "device model" | awk -F ':' '{print $2}' | sed -e 's/^[ \t]*//g'`
                diskserial=`smartctl /dev/$os -a | grep -i serial | awk -F ':' '{print $2}' | sed -e 's/^[ \t]*//g'`
                echo "$ps : /dev/$os : $diskserial : $diskmodel" | tee -a result-$t.txt
        else
                echo "$ps : Be absent !" | tee -a result-$t.txt
        fi
}
done < ph.csv
}
function total(){
n=`lsscsi | grep -i ata | wc -l`
if [[ n -lt 62 ]];then
        echo "Warning:There are $((62-$n)) disks are absent ! please check"
else
        echo "All disks are present! "
fi

}
total
touch_physical_hba_os
check_present
output
sleep 1
rm -rf os.csv
rm -rf present.txt
rm -rf ph.csv

上一篇 下一篇

猜你喜欢

热点阅读