Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created June 25, 2013 19:44
Show Gist options
  • Save hgdeoro/5861722 to your computer and use it in GitHub Desktop.
Save hgdeoro/5861722 to your computer and use it in GitHub Desktop.
Check health of SAS drive using smartctl
#!/bin/bash
#STATE_OK=0
#STATE_WARNING=1
#STATE_CRITICAL=2
#STATE_UNKNOWN=3
#STATE_DEPENDENT=4
STATUS_OK="OK"
STATUS_WARNING="WARNING"
STATUS_CRITICAL="CRITICAL"
STATUS_UNKNOWN="UNKNOWN"
if [ -z "$1" ] ; then
echo "$STATUS_CRITICAL - Must specify device"
exit 2
fi
TMP=$(mktemp)
smartctl -d scsi -H $1 > $TMP 2>&1
EXIT_STATUS=$?
if [ "$EXIT_STATUS" -ne "0" ] ; then
echo "$STATUS_CRITICAL - smartctl $1: exit status: $EXIT_STATUS - $(cat $TMP | egrep '^SMART Health Status:' )"
rm -f $TMP > /dev/null 2> /dev/null
exit 2
fi
## Exit status == 0
if [ "$(cat $TMP | egrep '^SMART Health Status:' | cut -d : -f 2)" = " OK" ] ; then
echo "$STATUS_OK - smartctl $1: OK"
rm -f $TMP > /dev/null 2> /dev/null
exit 0
else
echo "$STATUS_CRITICAL - smartctl $1: exit status: $EXIT_STATUS - $(cat $TMP | egrep '^SMART Health Status:' )"
rm -f $TMP > /dev/null 2> /dev/null
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment