Automatically Check The Raspberry Pi's Temperature (+Prevent Overheating)

No need to install anything. Just open a terminal and execute the following command to get the temperature of your RasPi.
/opt/vc/bin/vcgencmd measure_temp

Automate the process

The below script will automatically reboot your Raspberry Pi should it reach a specified threshold (maxtemp). First of all make sure you can reboot/shutdown your raspi without linux asking you for a password. 

user@user:~$ sudo visudo
Add the following to the sudoers file. 
user ALL=NOPASSWD: /sbin/shutdown

The script

Save as Maxtemp specifies the temperature cut-off point, at which the Raspi will reboot. 
#description     :Checks Temperature of Raspberry Pi and reboots at maxtemp.  
#author          :Mike M |  
#notes           :Add "user ALL=NOPASSWD: /sbin/shutdown" to sudoers file   
temp=`/opt/vc/bin/vcgencmd measure_temp | cut -c 6-7`  
if [ $temp -ge $maxtemp ]; then  
xmessage  "Alert! Temp above 75. System rebooting in 3 minutes"  
sudo /sbin/shutdown -r +3  
elif [ $temp -lt $maxtemp ]; then  
exit 0  

Create a cronjob

user@user:~$ sudo crontab

Add the following

*/5 * * * * sh /home/user/
This will run the script every 5 minutes and make sure that the Raspberry Pi does not overheat.


Popular posts from this blog

How to be anonymous on the internet (99-100%)

Deep Web Link List (.onion)