Skip to content

Instantly share code, notes, and snippets.

@i3luefire
Forked from fkleon/temperature.sh
Last active December 8, 2023 07:24
Show Gist options
  • Save i3luefire/242844141fde57d5cafd to your computer and use it in GitHub Desktop.
Save i3luefire/242844141fde57d5cafd to your computer and use it in GitHub Desktop.
This is a variation of fkleon's temperature.sh script that puts the info in a simple text file instead of an email. It is also my first gist on github. :)
#! /bin/sh
# This is your log filename
LOGFILE=/path/to/temp.log
# Create empty file
touch $LOGFILE
# 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" >> $LOGFILE
elif [ "$CM" = "00" ] ; then
echo " IDLE" >> $LOGFILE
else
echo " UNKNOWN ($CM)" >> $LOGFILE
fi
}
# Write some general information
echo System Temperatures - `date` >> $LOGFILE
cat /etc/version >> $LOGFILE
uptime | awk '{ print "\nSystem Load:",$10,$11,$12,"\n" }' >> $LOGFILE
# Write CPU temperatures
echo "CPU Temperature:" >> $LOGFILE
sysctl -a | egrep -E "cpu\.[0-9]+\.temp" >> $LOGFILE
echo >> $LOGFILE
# Write HDD temperatures and status
echo "HDD Temperature:" >> $LOGFILE
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 }'` >> $LOGFILE;
adastat $i;
done
# Make a seperator
echo " " >> $LOGFILE
echo "###############################################################################" >> $LOGFILE
echo " " >> $LOGFILE
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment