Skip to content

Instantly share code, notes, and snippets.

@zflat
Last active May 12, 2021 16:55
Show Gist options
  • Save zflat/e452d4a48822a82d4960cf82d8d46bc2 to your computer and use it in GitHub Desktop.
Save zflat/e452d4a48822a82d4960cf82d8d46bc2 to your computer and use it in GitHub Desktop.
Script to print CPU temperature in a while loop to STDOUT
#!/usr/bin/env bash
# Script to print CPU temperature in a while loop to STDOUT
if [ -z $1 ]; then
echo "Required THERMAL_ZONE arg not given." 1>&2
echo "List thermal zones and types with:" 1>&2
echo " grep . /sys/class/thermal/thermal_zone*/type" 1>&2
echo "" 1>&2
echo "Usage:" 1>&2
echo " $0 THERMAL_ZONE [SECONDS_BETWEEN_READINGS]" 1>&2
exit 1;
fi
echo "\"stamp\",\"thermal_zone${1}\""
while [ 1 ]; do
## Get a list of core temps and record the max?
## grep . /sys/devices/platform/coretemp.0/hwmon/hwmon*/temp*_input
# temps=$(cat /sys/devices/platform/coretemp.0/hwmon/hwmon*/temp*_input);
# max_temp=0
# for temp in $temps; do
# if [ "$temp" -gt "$max_temp" ]; then
# max_temp=$temp
# fi
# done
# cpu_temp=$(($max_temp / 1000))
# https://leo3418.github.io/2021/02/09/linux-cpu-freq-temp-mon-script.html
cpu_temp=$(($(cat "/sys/class/thermal/thermal_zone${1}/temp") / 1000))
echo "\"$(date -Iseconds)\", ${cpu_temp}"
sleep ${2:-1}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment