Skip to content

Instantly share code, notes, and snippets.

@raidzero
Created March 3, 2014 00:15
Show Gist options
  • Save raidzero/9316201 to your computer and use it in GitHub Desktop.
Save raidzero/9316201 to your computer and use it in GitHub Desktop.
CPU core temperature monitoring utility
#!/bin/sh
# cpu core temp monitor tool for my i7 4930k
SENSOR="coretemp-isa-0000"
COLUMNS=`tput cols`
if [ "$COLUMNS" -lt 106 ]; then
echo "Terminal needs to be 106 columns wide for hottestcore to work correctly."
exit 1
fi
HOTTEST=0
STARTTIME=`date +%s`
function coretemp()
{
CORE=$1
if [ -z "$CORE" ]; then
echo "USAGE: coretemp CORENUMBER [ 1 - 6 ]"
exit 1
fi
if [ $CORE -ge 1 ] && [ $CORE -le 6 ]; then
sensors $SENSOR | sed '1d;2d;/^$/d' | grep -v Physical | awk '{ if (NR=='"$CORE"') {print$3} }' | cut -d . -f1 | sed 's/+//g'
else
echo "Invalid core specified!"
fi
}
function listcores()
{
coretemp 1
coretemp 2
coretemp 3
coretemp 4
coretemp 5
coretemp 6
}
function surfacetemp()
{
sensors | grep "CPU Temp" | cut -d':' -f2 | sed 's/^ *+//g' | cut -d ' ' -f1
}
function CPUfanspeed()
{
sensors | grep "CPU Intake" | grep RPM | cut -d ':' -f2- | sed 's/^[ \t]*//g'
}
function avgtemp()
{
echo "scale=1; ($(coretemp 1)+$(coretemp 2)+$(coretemp 3)+$(coretemp 4)+$(coretemp 5)+$(coretemp 6))/6" | bc
}
function cpu_vcore()
{
echo "`sensors | grep Vcore | cut -d ':' -f2- | sed 's/^ *+//' | cut -d ' ' -f1 | sed 's/ $//'`v"
}
while [ 1 == 1 ]; do
RUNNING=`date +%s`
HOTTEST2=`listcores | sort -rk1 | head -n 1`
if [ $HOTTEST2 -gt $HOTTEST ]; then
HOTTEST=$HOTTEST2
printf "(HIGHEST) CORE TEMP: $HOTTEST C\r"
fi
let s=$RUNNING-$STARTTIME
TIMER=`printf "%02d:%02d:%02d" $((s/3600)) $((s%3600/60)) $((s%60))`
printf "CPU SURFACE: \e[1;32m`surfacetemp`\e[0m VCORE: \e[1;32m`cpu_vcore`\e[0m \e[1;32m\e[0mCPU FAN: \e[1;34m`CPUfanspeed`\e[0m HIGHEST CORETEMP: \e[1;31m"$HOTTEST2"°C\e[0m MAX: \e[1;31m"$HOTTEST"°C \e[0mAVG: \e[1;31m`avgtemp`°C\e[0m $TIMER \r"
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment