Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FreeNAS / camcontrol disk spindown check shell script with logging
#!/bin/sh
###########################################################################
# spincheck.sh
#
# Determines the power status of given disks without waking them through
# usage of smartctl.
#
# Author: Niels Gandrass
# Version: 1.0
# Since: 15.05.2017
###########################################################################
##### BEGIN Config parameters #####
# Determines where the output log is written to
spinlogfile="spincheck.log"
#spinlogfile="/dev/null"
# Command used to log output
log_output="tee -a $spinlogfile"
# Prefix used for device matching
device_prefix="ada"
# Time between checks in seconds
interval=600
#### END Config parameters #####
# Clear logfile
#echo "" > $spinlogfile
# Get devicelist
devices=`camcontrol devlist | grep ada | sed "s/.*(.*,\($device_prefix[0-9]*\))/\1/"`
# Print devicelist-header
printf "%20s" "" | $log_output
for device in $devices; do
printf "%5s" $device | $log_output
done
printf "\n" | $log_output
# Main loop
while [ 1 ]; do
printf "%20s" "`date +"%d.%m.%Y %H:%M:%S"`" | $log_output
for device in $devices; do
printf "%5s" "`camcontrol cmd $device -a "E5 00 00 00 00 00 00 00 00 00 00 00" -r - | cut -d " " -f 10 | sed "s/FF/1/" | sed "s/00/0/"`" | $log_output
done
printf "\n" | $log_output
sleep $interval
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment