From dc90c0ea3261a20e14f9970d1aa93ee69af40be9 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Wed, 11 Jun 2014 00:44:07 +0000 Subject: [PATCH] Script to blink lights on a HD enclosure by chrisrd found at https://github.com/zfsonlinux/zfs/issues/2375#issuecomment-45689003 --- blink-lights.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 blink-lights.sh diff --git a/blink-lights.sh b/blink-lights.sh new file mode 100755 index 0000000..41f2a91 --- /dev/null +++ b/blink-lights.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# +# Usage: disk-blink [--off] /dev/sd??? +# +# ACHTUNG! +# ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! +# DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! +# ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN +# MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN +# SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN +# UND WATSCHEN DER BLINKENLICHTEN. +# +function usage +{ + cat <&2 "${dev}: not a block device"; exit 1; } + +sasaddr=$( + lsscsi -tg | + sed -rn 's/.*sas:(0x[[:xdigit:]]+).*'"${dev//\//\\/}"'[[:space:]].*/\1/ p' +) +[ "${sasaddr}" ] || { echo "${dev}: SAS address not found"; exit 1; } + +# +# Scan all the enclosures for our SAS address +# +for encldev in $(lsscsi -tg | awk '$2 == "enclosu" { print $5 }') +do + # + # Note: we discard errors from sg_ses as, at version 1.64 20120118, + # it prints an error on some enclosures like: + # + # $ sg_ses -j /dev/sg45 > /dev/null + # join_work: oi=6, ei=255 (broken_ei=0) not in join_arr + # + # See Also: http://thread.gmane.org/gmane.linux.scsi/81514 + # + slot=$( + sg_ses -j "${encldev}" 2> /dev/null | + egrep "^Slot |^\s+SAS address:" | + grep -B1 ${sasaddr} | + awk '/^Slot/ { print $2 }' + ) + [ "${slot}" ] && break +done +[ "${slot}" ] || { echo 2>&1 "${dev}: enclosure/slot not found"; exit 1; } + +# +# Light 'em up +# +sg_ses -D "Slot ${slot}" "${action}" "${encldev}" + +exit 0 \ No newline at end of file