Raspberry Pi B+ CPU & GPU temperature monitor bash script

This script helps you monitor CPU and GPU temperatures of your RPi every ten minutes. Values are exported to a .csv file and location of your choice.

You can stop and start the script whenever you want. Values will be written after the last one, if you select the same file.

Create a file on your Desktop and name it for example cpugputemp.sh. Open file, copy/paste and save the code below.

(run the script in terminal with this command: bash /yourlocation/cpugputemp.sh).

#!/bin/bash

#Raspberry Pi Temperature Monitor
#Built by Zeus-www.thelinuxterminal.com
#For more info, drop a mail: office@thelinuxterminal.com

read -p "Enter location and filename (e.g. /root/Desktop/cpugpu_temp.csv): " cpugputemp
cpugpu_temp_file="$cpugputemp"
get_date=$(date +%d/%m/%y)
get_time=$(date +%H:%M)
if [ ! -f $temp_file ];
then
echo "Date,CPU Temp,GPU Temp" >> $cpugpu_temp_file
while :
do
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp | cut -d '=' -f2)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$((cpuTemp2 % $cpuTemp1))
gpuTemp=$(/opt/vc/bin/vcgencmd measure_temp | cut -d '=' -f2)
get_date_time=$(date "+%Y/%m/%d %H:%M:%S")
echo ""$get_date_time","$cpuTemp1"."$cpuTempM"'C","$gpuTemp"
sleep 600
done >> $cpugpu_temp_file
else
while :
do
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp | cut -d '=' -f2)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$((cpuTemp2 % $cpuTemp1))
gpuTemp=$(/opt/vc/bin/vcgencmd measure_temp | cut -d '=' -f2)
get_date_time=$(date "+%Y/%m/%d %H:%M:%S")
echo ""$get_date_time","$cpuTemp1"."$cpuTempM"'C","$gpuTemp"
sleep 600
done >> $cpugpu_temp_file
fi

Creative Commons License
Raspberry Pi B+ CPU & GPU Temperature Monitor by The Linux Terminal is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.