Skip to content

Instantly share code, notes, and snippets.

@AndreiTelteu
Last active October 28, 2020 20:17
Show Gist options
  • Save AndreiTelteu/11dae86616b48578a8e8649802414aaa to your computer and use it in GitHub Desktop.
Save AndreiTelteu/11dae86616b48578a8e8649802414aaa to your computer and use it in GitHub Desktop.
Get CPU, GPU and HDD temperatures

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

@AndreiTelteu
Copy link
Author

If you want this script to auto-update, create another script called temps-monit in the same folder (example nano .local/bin/temps-monit)

#!/bin/bash
while true; do clear && temps ; sleep ${1-1}; done

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.

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