Last active
July 2, 2021 12:16
-
-
Save benok/c117badbfb6af744578d48e2ab1d4d4f to your computer and use it in GitHub Desktop.
blink disk drive's led (useful for disk array using LSI Logic HBA to locate failed drive, etc.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# blink disk drive's led (useful for disk array using LSI Logic HBA to locate failed drive, etc.) | |
# https://gist.github.com/benok/c117badbfb6af744578d48e2ab1d4d4f | |
# (based from https://stackoverflow.com/a/4018229/26736) | |
# need blockdev(8) to clear disk cache on access | |
usage() { | |
echo "${0##*/} [-n] device(sda,sdb,etc.)" | |
echo "-n: suppress message" | |
} | |
opt_n=0 | |
vecho() { | |
if [ $opt_n != 1 ]; then | |
echo $* | |
fi | |
} | |
if [ ${1:-0} == '-n' ]; then | |
opt_n=1 | |
shift | |
fi | |
if [ $# != 1 ]; then | |
usage | |
exit 1 | |
fi | |
blockdev=$(which blockdev) | |
if [ $? != 0 ]; then | |
echo 'need blockdev(8) to run properly' | |
exit 1 | |
fi | |
uid=`id -u` | |
if [ $uid != 0 ]; then | |
echo 'you must be root.' | |
exit 1 | |
fi | |
diskDev=$1 | |
while true; do | |
vecho "accessing /dev/$diskDev..." | |
blockdev --flushbufs /dev/$diskDev | |
dd_err=$(dd if=/dev/$diskDev of=/dev/null bs=512 count=409600 conv=noerror 2>&1) | |
if [ $? != 0 ]; then | |
echo got error status $? from dd | |
echo $dd_err > /dev/stderr | |
exit 2 | |
fi | |
vecho "sleeping..." | |
sleep 2 | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment