Created
November 6, 2014 15:13
-
-
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
This file contains hidden or 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
| #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