-
Notifications
You must be signed in to change notification settings - Fork 1
/
smartinfo
executable file
·49 lines (43 loc) · 1.05 KB
/
smartinfo
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
#!/bin/bash
# Get device S.M.A.R.T. and store in appropriate file.
set -e
die() {
echo $1
exit 1
}
get_file_name() {
sn=$(sed -n 's/^Serial Number: \+//ip' < "$1")
dm=$(sed -n 's/^\(Device Model\|Product\): \+//ip' < "$1")
printf 'smart-%s-%s-%s.txt' "$dm" "$sn" "$(date +%F-%H-%M-%S)" | tr ' ' '_'
}
smart_bits() {
code=$1
echo "WARNING: S.M.A.R.T. exit code was $code"
echo -n "Check man 8 smartctl for EXIT STATUS section on bits: "
val=$code
mask=1
for i in 0 1 2 3 4 5 6 7; do
if ((($val & $mask) && 1)) ; then
echo "$i "
fi
mask=$((mask << 1))
done
echo
}
[ -b "$1" ] && DEVICE="$1" || die 'First parameter must be block device.'
tmp=$(tempfile)
sudo smartctl -x "$DEVICE" > "$tmp" || smart_bits $? 1>&2
fname=$(get_file_name "$tmp")
if [ -f "$fname" ] ; then
echo "File $fname already exists. Override? [yN] "
read answer
case "$answer" in
y|Y)
;;
*)
exit 0
;;
esac
fi
mv "$tmp" "$fname"
echo "File: $fname"