Oct 142017

While building my Pi 3 cluster I looked around for an easy bash script to monitor the CPU temperature. I found Vivek Gite’s original script worked nicely but I wanted it to monitor continuously until I stopped the script, I wanted the CPU temperature to be reported with the same precision as the GPU temperature and lastly, I wanted to discard the “temp=” output in the GPU temperature. To achieve all that, I edited the script and installed bc on the system (for the CPU temperature precision):

pi@localhost:~ $ sudo apt-get install bc

The following script continuously monitors temperatures for the CPU and GPU.

# Display the CPU and GPU temperature of the Raspberry Pi 3
# Author: Samuel Trassare (trassare.com) based on original script by Vivek Gite (cyberciti.biz) under GPL v2.x+
# Requires bc for proper formatting of the CPU temperature.

cpu=$(echo "scale=1; `cat /sys/class/thermal/thermal_zone0/temp` / 1000.0" | bc)

echo "$(date) @ $(hostname)"
echo "Press [ctrl+c] to end monitoring"

while true
  echo ""
  echo "CPU => $cpu'C"
  echo "GPU => $(/opt/vc/bin/vcgencmd measure_temp | cut -d = -f2)"
  sleep 3s

You can set the wait time between temperature reads by editing the line

  sleep 3s

to whatever you want.

Some folks have pointed out that the CPU and GPU don’t need to be read separately as both sensors are on the same SOC however I have noticed that the two sensors frequently report slightly different temperatures so I want them both reported.

This script can be downloaded from its github repository.