Skip to content

Instantly share code, notes, and snippets.

@fbettag
Last active December 5, 2015 16:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbettag/758963c2d4fec6255e14 to your computer and use it in GitHub Desktop.
Save fbettag/758963c2d4fec6255e14 to your computer and use it in GitHub Desktop.
Find harddisks programmatically in shell under FreeBSD while also identifying SMART capability
#!/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