Create a new file called temps
in a folder that is included in PATH (example nano .local/bin/temps
)
#!/bin/bash
# Purpose: Display the ARM CPU and GPU temperature of Raspberry Pi 2/3
# Author: Vivek Gite <www.cyberciti.biz> under GPL v2.x+
# source: https://www.cyberciti.biz/faq/linux-find-out-raspberry-pi-gpu-and-arm-cpu-temperature-command/
# modified by: Andrei Telteu https://gist.github.com/AndreiTelteu/11dae86616b48578a8e8649802414aaa
# -------------------------------------------------------
cpu=$(</sys/class/thermal/thermal_zone0/temp)
hdd=/dev/sda # lsblk -d to see all
echo "$(date +'%Y-%m-%d %T') @ $(hostname)"
echo "-------------------------------------------"
echo "CPU => $((cpu/1000))° C"
echo "GPU => $(/opt/vc/bin/vcgencmd measure_temp | egrep -o '[0-9]*\.' | egrep -o '[0-9]*')° C"
# method 1 for hdd temp; must have installed hddtemp; install with sudo apt-get install hddtemp
echo "HDD => $(sudo hddtemp sata:$hdd | egrep -o '\: [0-9]*' | egrep -o '[0-9]*')° C"
# method 2 for hdd temp; must have installed smartmontools; install with sudo apt-get install smartmontools
#echo "HDD => $(sudo smartctl -d sat -A -T permissive $hdd | grep Temperature_Celsius | egrep -o '[0-9]* \(' | egrep -o '[0-9]*')° C"
Give the file permission to execute: chmod +x .local/bin/temps
To change the HDD you want to monitor, first run lsblk -d
to see your available devices, then change the hdd variable.
If HDD temperature does not work, try method to by commenting the first echo HDD
and uncommenting the second one.
Credits to Vivek Gite @ cyberciti.biz for the initial script
If you want this script to auto-update, create another script called
temps-monit
in the same folder (examplenano .local/bin/temps-monit
)Give execute permission:
chmod +x .local/bin/temps-monit
Use it with
temps-monit
. It will update at 1 second interval.To change that pass the interval in seconds as the second parameter:
temps-monit 2
for 2 seconds,temps-monit 0.5
for half a second.