Skip to content

Instantly share code, notes, and snippets.

@andrewpmiller
Forked from ecampidoglio/cpustatus.sh
Last active August 29, 2015 14:17
Show Gist options
  • Save andrewpmiller/bcdb6457bc48a3f39937 to your computer and use it in GitHub Desktop.
Save andrewpmiller/bcdb6457bc48a3f39937 to your computer and use it in GitHub Desktop.
#!/bin/bash
# cpustatus
#
# Prints the current state of the CPU like temperature, voltage and speed.
# Temperature is reported in degrees Fahrenheit (F) - converting from C requires bc
# CPU speed is calculated in megahertz (MHz).
function convert_to_MHz {
let value=$1/1000
echo "$value"
}
function calculate_overvolts {
# We can safely ignore the integer
# part of the decimal argument
# since it's not realistic to run the Pi
# at voltages higher than 1.99 V
let overvolts=${1#*.}-20
echo "$overvolts"
}
# Read the temperature
tm=`/opt/vc/bin/vcgencmd measure_temp`
# Strip out the garbage
tc=`echo $tm| cut -d '=' -f2 | sed 's/..$//'`
# Convert to Fahrenheit
tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc)
volts=$(vcgencmd measure_volts)
volts=${volts:5:4}
if [ $volts != "1.20" ]; then
overvolts=$(calculate_overvolts $volts)
fi
minFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq)
minFreq=$(convert_to_MHz $minFreq)
maxFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq)
maxFreq=$(convert_to_MHz $maxFreq)
freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
freq=$(convert_to_MHz $freq)
governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
echo "Temperature: $tf F"
echo -n "Voltage: $volts V"
[ $overvolts ] && echo " (+0.$overvolts overvolt)" || echo -e "\r"
echo "Min speed: $minFreq MHz"
echo "Max speed: $maxFreq MHz"
echo "Current speed: $freq MHz"
echo "Governor: $governor"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment