Last active
December 5, 2015 16:56
-
-
Save fbettag/758963c2d4fec6255e14 to your computer and use it in GitHub Desktop.
Find harddisks programmatically in shell under FreeBSD while also identifying SMART capability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DEVICES=`/sbin/camcontrol devlist | /usr/bin/egrep -oe '\(\w*\d*'| /usr/bin/sed -e 's;^(;;g'` | |
for DEVICE in $DEVICES; do | |
NEED_SMART=`/sbin/camcontrol identify $DEVICE | /usr/bin/egrep -coe '^SMART.*yes.*no.*'` | |
if [ $NEED_SMART -eq 1 ] && [ -f "/usr/local/sbin/smartctl" ]; then | |
/usr/local/sbin/smartctl -s on /dev/$DEVICE | |
[ $? -eq 0 ] && echo "Enabled SMART for $DEVICE" 1>&2 # output to STDERR so people see it while piping ;) | |
fi | |
# account for changes in enabling SMART | |
HAVE_SMART=`/sbin/camcontrol identify $DEVICE | /usr/bin/egrep -coe '^SMART.*yes.*'` | |
NEED_SMART=`/sbin/camcontrol identify $DEVICE | /usr/bin/egrep -coe '^SMART.*yes.*no.*'` | |
case "$DEVICE" in | |
acd*) ;; | |
ses*) ;; | |
*) | |
echo -n $DEVICE | |
if [ $HAVE_SMART -ne 1 ]; then | |
echo # newline | |
elif [ $HAVE_SMART -eq 1 ] && [ $NEED_SMART -eq 0 ]; then | |
echo " (SMART)" | |
else | |
echo " (SMART disabled)" | |
fi | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment