Skip to content

Instantly share code, notes, and snippets.

@arpanpal010
Created November 6, 2014 15:13
Show Gist options
  • Select an option

  • Save arpanpal010/ddc54fd857c4ca6244c9 to your computer and use it in GitHub Desktop.

Select an option

Save arpanpal010/ddc54fd857c4ca6244c9 to your computer and use it in GitHub Desktop.
Simple CPU temperature monitor, also displays core speeds if available. Requires manual setting of temperature sources
#tempmon modified
function tempmon() {
# datadir="$HOME/tempinfo";
datadir="/tmp/tempinfo";
# rm -rf $datadir;
mkdir -p $datadir;
sleeptime=10; #seconds
#loop
while true;
do
#core freq
#if cpuinfo
if [ "`cat /proc/cpuinfo | grep "cpu MHz"`" ];
then
#echo "Clock Speed(s) MHz:";
#for item in `cat /proc/cpuinfo | grep "cpu MHz" | sed s'/ //'g | sed s'/cpu MHz//'g | sed s'/://'g`;
#do echo $item;
#done;
cpufreqs=(`cat /proc/cpuinfo | grep "cpu MHz" | sed s'/ //'g | sed s'/cpu MHz//'g | sed s'/://'g`);
fi;
#temp
coreno=0;
#temp sources
tempsrc="/sys/class/hwmon/hwmon0"; #desktop
tempnamereg="temp*_input";
#tempsrc="/sys/class/thermal/thermal_zone0/"; #pi
#tempnamereg="temp";
#read sensor paths and pass to monitor
for temp in `ls $tempsrc/$tempnamereg | sort`;
do
#get sensors
#sensor="${temp%_*}";
#echo $temp;
#tempfilename=`basename $temp`;
#echo $tempfilename;
avgtemp=0;
hightemp=0;
lowtemp=0;
newtemp=`cat $temp`;
#let newtemp/=1000;
path_avgtemp="$datadir/`basename $temp`_avg"
path_hightemp="$datadir/`basename $temp`_high"
path_lowtemp="$datadir/`basename $temp`_low"
if [ -f "$path_hightemp" ];
then hightemp=`cat $path_hightemp`;
fi;
#check if highest
if [ $newtemp -gt $hightemp ];
then
let hightemp=$newtemp;
echo $hightemp > $path_hightemp;
fi;
if [ -f "$path_lowtemp" ];
then lowtemp=`cat $path_lowtemp`;
fi;
#check if lowest
if [ $newtemp -lt $lowtemp ] || [ $lowtemp == 0 ];
then
let lowtemp=$newtemp;
echo $lowtemp > $path_lowtemp;
fi;
if [ -f "$path_avgtemp" ];
then avgtemp=`cat $path_avgtemp`;
else let avgtemp=$newtemp;
fi;
#get average
let avgtemp=$avgtemp+$newtemp;
let avgtemp/=2;
if [ $avgtemp != $newtemp ] || [ ! -f "$path_avgtemp" ];
then
echo $avgtemp > $path_avgtemp;
fi;
#display
echo "Core:$coreno[${cpufreqs[$coreno]}MHz]-> Current:$newtemp / Avg:$avgtemp / High:$hightemp / Low:$lowtemp";
let coreno+=1;
done;
sleep $sleeptime;
clear;
done;
}
tempmon;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment