-
Notifications
You must be signed in to change notification settings - Fork 118
/
check_osx_smart.sh
executable file
·85 lines (71 loc) · 1.17 KB
/
check_osx_smart.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
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
#!/usr/bin/env bash
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
usage()
{
cat <<EOF
Check the S.M.A.R.T status for a disk on OSX.
Options:
-d <disk> Specify volume a disk
-l List available disks
Usage: $0 -d disk0
EOF
}
argcheck() {
# if less than n argument
if [ $ARGC -lt $1 ]; then
echo "Missing arguments! Use \`\`-h'' for help."
exit 1
fi
}
CHECK=0
ARGC=$#
argcheck 1
while getopts "hld:" OPTION
do
case $OPTION in
h)
usage
;;
l)
diskutil list
exit 0
;;
d)
CHECK=1
DISK="$OPTARG"
;;
\?)
exit 1
;;
esac
done
if [ $CHECK -eq 1 ]; then
if [ -b /dev/${DISK} ]; then
STATUS=$(diskutil info $DISK | awk '/SMART/ { print $3 }')
else
echo "$DISK is not a valid block device"
exit 3
fi
case $STATUS in
[vV]erified)
echo "Disk $DISK is OK."
exit $OK
;;
*[nN]ot*)
echo "SMART status is not supported for this disk (e.g. externals): $DISK"
exit $OK
;;
*[fF]ail*)
echo "Disk $DISK is failing."
exit $CRITICAL
;;
*)
echo "Unknown status for $DISK: $STATUS"
exit $UNKNOWN
;;
esac
fi