How to Get the CPU Temperature on Raspberry PI using BASH Script?


Raspberry PI is a credit-card size fully functional PC. You can install Linux on it. The CPU is ARM 700MHz for both A and B models. However, it is so tiny that it doesn’t come with a CPU fan on the board. It doesn’t have a power button either; the Raspberry PI uses a micro USB power adapter that is 5V and 1000 mA. Once you plug the micro USB, it is on. The Raspberry PI is often used as the server for home usages such as file sharing, printer sharing. And you can also host your website (Apache, PHP and MySQL) on it. So one serious problem of using Raspberry PI for long time is the heat problem.

Does it still work well if left on for days or even months? Does the heat/temperature stay under controlled? What is the longest uptime?

raspberry-pi-pi How to Get the CPU Temperature on Raspberry PI using BASH Script? BASH bash script CPU hardware Raspberry PI Technology

We can use /usr/bin/uptime to return the uptime since Raspberry PI was booted. Or this command cat /proc/uptime returns the uptime in unix time format.

We can use cat /sys/class/thermal/thermal_zone0/temp to print out the temperature in millicentigrade. To give a user-friendly temperatures, we can create a bash script e.g. temp and give it the execution attributes chmod +x temp.

1
2
3
4
5
#!/bin/bash
 
temp=`cat /sys/class/thermal/thermal_zone0/temp`
 
echo "CPU Temperature: $(($temp/1000)) C = $(($temp/1000*9/5+32))F"
#!/bin/bash

temp=`cat /sys/class/thermal/thermal_zone0/temp`

echo "CPU Temperature: $(($temp/1000)) C = $(($temp/1000*9/5+32))F"

This will give something like this:

pi@raspberrypi:~$ ./temp
CPU Temperature: 49 C = 120F

So, keep an eye on the temperature. I will put an external USB fan to drop down the temperature soon.

With a cooling fan, I manage to cool down the CPU temperature down to less than 30 degree on Raspberry PI 4B: How to Monitor the CPU Temperature of Raspberry PI using Python Script?

Raspberry Pi

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
463 words
Last Post: Running Apache Server (PHP + MySQL) on Raspberry PI
Next Post: Parentheses in VBScript

The Permanent URL is: How to Get the CPU Temperature on Raspberry PI using BASH Script?

Leave a Reply