Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active January 10, 2026 15:57
Show Gist options
  • Select an option

  • Save Hermann-SW/0c3690624375295ddfac919295169222 to your computer and use it in GitHub Desktop.

Select an option

Save Hermann-SW/0c3690624375295ddfac919295169222 to your computer and use it in GitHub Desktop.
Determine temerature statistics for sockets and cores
#!/bin/bash
nsockets=$(grep "physical id" /proc/cpuinfo | sort -u | wc -l)
for((i=0; i<nsockets; ++i))
do
coretemp=$(sensors -A | sed -n "/^coretemp-isa-000$i/,/^$/p")
echo "$coretemp" | grep "Package" | sort
high=$(echo "$coretemp" | grep "Core" | cut -b17- | grep high | sort -n)
ts=$(
(
echo "$high" | sort -n | head -1
echo "$high" | sort -n | \
awk '{ total += $1; count++ } END { printf("%.2f°C\n", total/count) }'
echo "$high" | sort -n | tail -1
) | ( cut -f1 -d\ )
)
echo -n $ts # double quoting as shellcheck suggests would break formatting
echo -e "\t(min/avg/max of $(echo "$coretemp" | grep -c "Core")"" cores)"
done
@Hermann-SW
Copy link
Author

Script does not work on single socket machines.
Just installed lm-sensors on another 2-socket server:
https://www.cyberciti.biz/faq/install-sensors-lm-sensors-on-ubuntu-debian-linux/

coretemps just works, temperatures and correct core count per package:

hermann@E5-2680v4:~$ coretemps 
Package id 0:  +42.0°C  (high = +90.0°C, crit = +100.0°C)
35.0°C 35.79°C 38.0°C	(min/avg/max of 14 cores)
Package id 1:  +39.0°C  (high = +90.0°C, crit = +100.0°C)
33.0°C 34.29°C 35.0°C	(min/avg/max of 14 cores)
hermann@E5-2680v4:~$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment