Created
August 3, 2013 18:27
-
-
Save fkleon/6147471 to your computer and use it in GitHub Desktop.
FreeBSD / FreeNAS script to send a status report containing CPU and HDD temps and status to a given email address.
Tested on FreeNAS 9.1.0-RELEASE (based on FreeBSD 9-STABLE). Based on the script available at http://forums.freenas.org/threads/how-to-monitor-system-cpu-hdd-mobo-gpu-temperatures-on-freenas-8.2994/#post-38847.
This file contains 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
#! /usr/local/bin/sh | |
# Write email header to temp file | |
( | |
echo "To: your@email" | |
echo "Subject: System Temperatures INFO" | |
echo " " | |
) > /var/cover | |
# Define adastat function, which writes drive activity to temp file | |
adastat () { | |
CM=$(camcontrol cmd $1 -a "E5 00 00 00 00 00 00 00 00 00 00 00" -r - | awk '{print $10}') | |
if [ "$CM" = "FF" ] ; then | |
echo " SPINNING" >> /var/cover | |
elif [ "$CM" = "00" ] ; then | |
echo " IDLE" >> /var/cover | |
else | |
echo " UNKNOWN ($CM)" >> /var/cover | |
fi | |
} | |
# Write some general information | |
echo System Temperatures - `date` >> /var/cover | |
cat /etc/version >> /var/cover | |
uptime | awk '{ print "\nSystem Load:",$10,$11,$12,"\n" }' >> /var/cover | |
# Write CPU temperatures | |
echo "CPU Temperature:" >> /var/cover | |
sysctl -a | egrep -E "cpu\.[0-9]+\.temp" >> /var/cover | |
echo >> /var/cover | |
# Write HDD temperatures and status | |
echo "HDD Temperature:" >> /var/cover | |
for i in $(sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--) if(match($i, '/ada/')) print $i }' ) | |
do | |
echo -n $i: `smartctl -a /dev/$i | awk '/Temperature_Celsius/{DevTemp=$10;} /Serial Number:/{DevSerNum=$3}; /Device Model:/{DevVendor=$3; DevName=$4} \ | |
END {printf "%s C - %s %s (%s) - ", DevTemp,DevVendor,DevName,DevSerNum }'` >> /var/cover; | |
adastat $i; | |
done | |
# Send status email | |
sendmail -t < /var/cover | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment