~ubuntu-branches/debian/sid/sg3-utils/sid

« back to all changes in this revision

Viewing changes to scripts/sas_disk_blink

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-11-05 20:42:13 UTC
  • mfrom: (5.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091105204213-ug7wrb6m7l9kmvyg
* QA upload.
* Add libsgutils2-2.symbols.kfreebsd. Some of the symbols are Linux
  specific causing FTBFS on kfreebsd.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# sas_disk_blink
3
 
#
4
 
# Script to blink the LED on a SAS disk.
5
 
# By default it blinks the LED for 30 seconds, thereafter leaving
6
 
# the LED in the state it was prior to this command being called.
7
 
# The blink is one second on, one second off, etc.
8
 
#
9
 
# Uses sdparm rather than sg3_utils as the former is simpler to
10
 
# use for setting mode page value.
11
 
#
12
 
# Douglas Gilbert 20070317
13
 
 
14
 
 
15
 
seconds=30
16
 
 
17
 
usage()
18
 
{
19
 
  echo "Usage: sas_disk_blink [-h] [-s <n>] <sas_device>"
20
 
  echo "  where:"
21
 
  echo "    -h, --help           print usage message"
22
 
  echo "    -s <n>, --set <n>    where <n> is:"
23
 
  echo "                           0  - set RLM to 0"
24
 
  echo "                           1  - set RLM to 1"
25
 
  echo "                           >1 - blink LED for <n> seconds"
26
 
  echo "                                (default: blink for 30 seconds)"
27
 
  echo ""
28
 
  echo "Use Ready LED Meaning (RLM) mode page field to blink SAS device LED"
29
 
}
30
 
 
31
 
if (( $# < 1 ))
32
 
  then
33
 
    usage
34
 
    exit 1
35
 
fi 
36
 
 
37
 
opt="$1"
38
 
while test ! -z "$opt" -a -z "${opt##-*}"; do
39
 
  opt=${opt#-}
40
 
  case "$opt" in
41
 
    h|-help) usage ; exit 0 ;;
42
 
    s|-set) shift ; let seconds=$1 ;;
43
 
    *) echo "Unknown option: -$opt " ; exit 1 ;;
44
 
  esac
45
 
  shift
46
 
  opt="$1"
47
 
done
48
 
 
49
 
if ( which sdparm >/dev/null 2>&1 ) ; then
50
 
  true
51
 
else
52
 
  echo "sdparm not found"
53
 
  sdparm
54
 
fi
55
 
 
56
 
if [ $seconds = "0" ]
57
 
then
58
 
    sdparm -t sas -c RLM $1
59
 
    exit $?
60
 
elif [ $seconds = "1" ]
61
 
then
62
 
    sdparm -t sas -s RLM $1
63
 
    exit $?
64
 
elif [ $seconds -gt 1 ]
65
 
then
66
 
    outt=$(sdparm -t sas -g RLM -H $1)
67
 
    let res=$?
68
 
    if [ $res -ne 0 ]
69
 
    then
70
 
        exit $res
71
 
    fi
72
 
    if [ ${outt:0:4} = "0x00" ]
73
 
    then
74
 
        let start=0
75
 
    else
76
 
        let start=1
77
 
    fi
78
 
    echo "start blinking for $seconds seconds"
79
 
    for (( times = 1; times < $seconds; times=$times+2 )); do
80
 
        if [ $start -eq 0 ]
81
 
        then
82
 
            sdparm -q -t sas -s RLM $1
83
 
            let res=$?
84
 
            if [ $res -ne 0 ]
85
 
            then
86
 
                exit $res
87
 
            fi
88
 
            sleep 1
89
 
            sdparm -q -t sas -c RLM $1
90
 
            sleep 1
91
 
        else
92
 
            sdparm -q -t sas -c RLM $1
93
 
            let res=$?
94
 
            if [ $res -ne 0 ]
95
 
            then
96
 
                exit $res
97
 
            fi
98
 
            sleep 1
99
 
            sdparm -q -t sas -s RLM $1
100
 
            sleep 1
101
 
        fi
102
 
    done
103
 
    echo "stop blinking"
104
 
fi