File: sas_disk_blink

package info (click to toggle)
sdparm 1.12-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: ansic: 30,669; sh: 5,745; makefile: 195
file content (109 lines) | stat: -rwxr-xr-x 2,599 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# sas_disk_blink
#
# Script to blink the LED on a SAS disk.
# By default it blinks the LED for 30 seconds, thereafter leaving
# the LED in the state it was prior to this command being called.
# The blink is one second on, one second off, etc.
#
# Uses sdparm rather than sg3_utils as the former is simpler to
# use for setting mode page value.
#
# Douglas Gilbert 20160224


seconds=30
verbose=""

usage()
{
  echo "Usage: sas_disk_blink [-h] [-s <n>] [-v] <sas_device>"
  echo "  where:"
  echo "    -h, --help           print usage message"
  echo "    -s <n>, --set <n>    where <n> is:"
  echo "                           0  - set RLM to 0"
  echo "                           1  - set RLM to 1"
  echo "                           >1 - blink LED for <n> seconds"
  echo "                                (default: blink for 30 seconds)"
  echo "    -v, --verbose        more verbose output"
  echo ""
  echo "Use Ready LED Meaning (RLM) mode page field to blink SAS device LED"
}

opt="$1"
while test ! -z "$opt" -a -z "${opt##-*}"; do
  opt=${opt#-}
  case "$opt" in
    h|-help) usage ; exit 0 ;;
    s|-set) shift ; let seconds="$1" ;;
    v|-verbose) verbose="-v" ;;
    vv) verbose="-vv" ;;
    vvv) verbose="-vvv" ;;
    *) echo "Unknown option: -$opt " ; exit 1 ;;
  esac
  shift
  opt="$1"
done

if [ $# -lt 1 ]
  then
    usage
    exit 1
fi 

if ( which sdparm >/dev/null 2>&1 ) ; then
  true
else
  echo "sdparm not found"
  sdparm
fi

if [ "$seconds" = "0" ]
then
    sdparm ${verbose} -t sas -c RLM "$1"
    exit $?
elif [ "$seconds" = "1" ]
then
    sdparm ${verbose} -t sas -s RLM "$1"
    exit $?
elif [ "$seconds" -gt 1 ]
then
    outt=$(sdparm ${verbose} -t sas -g RLM -H "$1")
    let res=$?
    if [ $res -ne 0 ]
    then
        exit $res
    fi
    if [ "${outt:0:4}" = "0x00" ]
    then
        let start=0
    else
        let start=1
    fi
    echo "start blinking for $seconds seconds"
    for (( times = 1; times < seconds; times=times+2 )); do
        if [ $start -eq 0 ]
        then
            sdparm ${verbose} -q -t sas -s RLM "$1"
            let res=$?
            if [ $res -ne 0 ]
            then
                exit $res
            fi
            sleep 1
            sdparm ${verbose} -q -t sas -c RLM "$1"
            sleep 1
        else
            sdparm ${verbose} -q -t sas -c RLM "$1"
            let res=$?
            if [ $res -ne 0 ]
            then
                exit $res
            fi
            sleep 1
            sdparm ${verbose} -q -t sas -s RLM "$1"
            sleep 1
        fi
    done
    echo "stop blinking"
fi