Skip to content

Instantly share code, notes, and snippets.

@jeffypooo
Last active December 13, 2020 21:43
Show Gist options
  • Save jeffypooo/b7dbfe9349b1f6962299379cdfc48d30 to your computer and use it in GitHub Desktop.
Save jeffypooo/b7dbfe9349b1f6962299379cdfc48d30 to your computer and use it in GitHub Desktop.
Raspberry Pi - Ubuntu - Get the CPU temperature and core frequency
#!/bin/bash
temp=$(</sys/class/thermal/thermal_zone0/temp)
freq_hz=$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq)
temp_f=`echo "$temp/1000" | bc -l`
freq_ghz_f=`echo "$freq_hz/1000000" | bc -l`
printf "CPU Temp: %.2f°C\n" $temp_f
printf "CPU Freq: %.2fGHz\n" $freq_ghz_f
@jeffypooo
Copy link
Author

Don't forget to make this executable:

chmod +x /path/to/script/tempc.sh

If you want to poll, use watch:

watch -n 1 "/path/to/script/tempc.sh"

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