smartctl与sas3ircu结合进行磁盘定位的方法

1. 首先通过smartctl查询磁盘的serial number;

    比如要查询sdg的磁盘序列号

smartctl -a /dev/sdg |grep Seri -A7 -B3

2. 通过sas3ircu命令,根据序列号查找该磁盘的对应的槽位。

sas3ircu 0 display |grep ZAD0A3WS -A2 -B7

红色的0:表示第几块sas卡,一般需要进行轮询,可以得到SAS卡的ID号,如下:

for SAS_ID in {0..2}
do
	ENCL=`sas3ircu ${SAS_ID}  display  |grep ${DEV_NUM} -A3 -B8 |grep Enclosure |awk '{print $NF}'`
	SLOT=`sas3ircu ${SAS_ID}  display  |grep ${DEV_NUM} -A3 -B8 |grep Slot |awk '{print $NF}'`
	if [ "" != "${SLOT}" ] && [ "" != "${ENCL}" ]
	then 
		echo -e "\033[33m [Enclosure]:${ENCL} [slot]: ${SLOT} \033[0m"
		break;
	fi
done

3. 根据槽位,ENCL编号以及sas卡ID号即可实现对该磁盘的指示灯点亮操作

 sas3ircu ${SAS_ID} locate ${ENCL}:${SLOT} on

     如上例:sas3ircu 0 locate 2:7 on //即可将sdg的指示灯点亮。

示例脚本如下:

#!/bin/sh 
############################################################
#    description:点亮磁盘定位灯
#    author     :axw2013
#    date       :2018-05-19
#    modify     :2018-07-27
############################################################  


if [ 2 -ne $# ]
then
	echo -e "\033[35m [USAGE: ] ./$0 [dev] [option] ; 将设备中的某个磁盘的灯点亮|关闭 \033[0m"
	echo -e "\033[33m     [eg:] ./$0 sda on \033[0m"
	echo -e "\033[33m     [eg:] ./$0 sdc off \033[0m"
	exit 0
fi 

DEV_NUM=`ls -l /dev/disk/by-id/ |grep ata |grep ${1}$ |awk '{print $9}'|awk -F "_" '{print $2}'`

echo -e "\033[33m [Device Number]: ${DEV_NUM} \033[0m"

for i in {0..2}
do
	ENCL=`sas3ircu $i display  |grep ${DEV_NUM} -A3 -B8 |grep Enclosure |awk '{print $NF}'`
	SLOT=`sas3ircu $i display  |grep ${DEV_NUM} -A3 -B8 |grep Slot |awk '{print $NF}'`
	if [ "" != "${SLOT}" ] && [ "" != "${ENCL}" ]
	then 
		echo -e "\033[33m [Enclosure]:${ENCL} [slot]: ${SLOT} \033[0m"
		break;
	fi
done

	sas3ircu ${i} locate ${ENCL}:${SLOT} ${2}
	if [ $? == 0 ]
	then
		echo -e "\033[33m set [/dev/$1] light [$2] successfully. \033[0m"
		exit 0;
	fi
	
	echo -e "\033[31m set [/dev/$1] light [$2] failure. \033[0m"

exit 1

注意:通过LU WWN Device Id -----> GUID 的对应关系也能实现定位磁盘

 

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值