forked from ffzg/gnt-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart-megaraid.sh
executable file
·38 lines (30 loc) · 1.21 KB
/
smart-megaraid.sh
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
#!/bin/sh
# Usage:
# smart-megaraid.sh '^# 1' # default without args
# SMART="-t long" smart-megaraid.sh # execute smart command
pattern='(^# [1-2]|test remaining|Hours|Error|Serial|Model|Firmware|Load|Reallocated|Pending|failure)'
test ! -z "$1" && pattern=$*
did_megaraid=0
megaraid() {
test $did_megaraid -eq 1 && return
drive=$1
nr=0
while [ $nr -lt 8 ] ; do
test ! -z "$SMART" && smartctl -d megaraid,$nr $SMART /dev/$drive > /dev/shm/smart.$drive.$nr-out
smartctl -d megaraid,$nr -a /dev/$drive > /dev/shm/smart.$drive.$nr
nr=`expr $nr + 1`
done
did_megaraid=1
}
test -r /proc/mdstat && cat /proc/mdstat
lsblk --noheadings --scsi -o name | while read drive ; do
test ! -z "$SMART" && smartctl $SMART /dev/$drive > /dev/shm/smart.$drive-out
smartctl -a /dev/$drive > /dev/shm/smart.$drive
if egrep -q '(PERC|MegaRaid|DELL)' /dev/shm/smart.$drive ; then
megaraid $drive
rm /dev/shm/smart.$drive
fi
done
grep 'Serial Number' /dev/shm/smart.sd* | cut -d: -f3| sort | uniq -c | grep -v ' 1 ' | awk '{ print $2 }' > /dev/shm/smart.duplicate && \
grep -l -f /dev/shm/smart.duplicate /dev/shm/smart.sd? | xargs -i rm -v {}
egrep -i "$pattern" /dev/shm/smart.* | grep -v -- '- *0$' | cut -d. -f2- | sed -e 's/:/\t/'