• Contact
  • About Me
  • Privacy Policy
  • Disclaimer
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Solutions

Solution: CPU Temperature Monitoring on Raspberry Pi

neo by neo
September 11, 2025
in Solutions
0
Solution: CPU Temperature Monitoring on Raspberry Pi4

Solution: CPU Temperature Monitoring on Raspberry Pi4

0
SHARES
36
VIEWS
Share on FacebookShare on LinkedIn
Table of Contents
  • Temperature Monitoring on Raspberry Pi Devices
    • Introduction
  • Raspberry Pi4 CPU temperature monitoring with bash script
  • Bash Script
  • Add the Script in the Crontab

Temperature Monitoring on Raspberry Pi Devices

Raspberry Pi boards come with a built-in temperature sensor, which can be accessed easily through the command line. Regular monitoring helps maintain system stability, especially during heavy workloads or extended usage. We’ll cover simple methods to check the CPU temperature using native tools like vcgencmd and cat, as well as how to set up automated monitoring to alert you when temperatures exceed safe thresholds.

Introduction

Monitoring the CPU temperature of Raspberry Pi 4 or any other Raspberry device is crucial for maintaining its performance and longevity, especially during demanding workloads or in warm environments. Overheating can lead to throttling, performance degradation, or even permanent hardware damage. By implementing a simple and efficient Bash script, you can monitor the CPU temperature in real time and take proactive measures to prevent overheating.

For instance, I observed that my Raspberry Pi 4 was reaching temperatures of around 70°C during the hottest part of the day. To address this, I decided to install a passive cooler and remove the top cover. These simple steps helped reduce the temperature by approximately 8-10°C.

In this article, we’ll guide you through the process of creating a Bash script to monitor the CPU temperature on your Raspberry Pi 4. Whether you’re running intensive applications or just curious about your device’s thermal health, this solution is straightforward to implement and highly customizable to meet your needs.

Raspberry Pi4 CPU temperature monitoring with bash script

I had an issue that during operation, my Raspberry Pi4 had a CPU temperature higher than 60 degrees Celsius. I wanted to check in which period of the day this happens, and I developed a script that periodically saved information about the temperature in a log file.

Bash Script

To check periodically temperature on my Raspberry Pi4 on Ubuntu 22.04 I developed the following script:

#!/bin/bash

LOG_FILE="/opt/scripts/log/check_temp_$(date +%Y-%m-%d).log" # Location for log file
echo "Check temperature script is executed on $(date)"  >> $LOG_FILE

# Loop indefinitely
while :
do
  temp=$(sensors| grep "temp1" | awk '{print $2}')
  echo "$(date): Temp: $temp" >> $LOG_FILE
  sleep 600
  # Check if the date has changed
  if [ "$(date +%Y-%m-%d)" != "$(date -r "$LOG_FILE" +%Y-%m-%d)" ]; then
     # Create a new log file for the new day
     LOG_FILE="/opt/scripts/log/check_temp_$(date +%Y-%m-%d).log"
     echo "Script is executed on $(date)" >> "$LOG_FILE"
  fi
done

You can save the script on the following script:

nano /opt/scripts/check_temp.sh

To make it executable:

ADVERTISEMENT
chmod +x /opt/scripts/check_temp.sh

Add the Script in the Crontab

To run it after every reboot, automatically add the following line in the cron:

ADVERTISEMENT
# Check temp
@reboot sleep 180 && sudo bash /opt/scripts/check_temp.sh

defencedev.com

About The Author

neo

See author's posts

ADVERTISEMENT
Previous Post

Ubuntu Internet Connection Monitoring Script: Log Creation and Email Alerts

Next Post

Linux Files Operation: wc (Word Count) Usage Examples

neo

neo

Related Posts

Install Portainer on Ubuntu 24.04 Using Docker Compose
Docker

Install Portainer on Ubuntu 24.04 Using Docker Compose

Automatic Windows Service Monitoring and Restart Script
Solutions

Automatic Windows Service Monitoring and Restart Script

Host a Website on Raspberry Pi – Real Benchmark Tests
Solutions

Host a Website on Raspberry Pi – Real Benchmark Tests

My Ultimate Docker Command Cheat Sheet (2025 Edition)
Docker

My Ultimate Docker Commands Cheat Sheet (2025 Edition)

Protect Docker-Hosted Application from HTTP Flood (DDoS) Attacks Using a Bash Script
Docker

Protect Docker-Hosted Application from HTTP Flood (DDoS) Attacks Using a Bash Script

Raspberry Pi Monitoring with Monit: Docker, Temperature, Network & More
Solutions

Raspberry Pi Monitoring with Monit: Docker, Temperature & More

Next Post
Linux Files Operation: wc (Word Count) Usage Examples

Linux Files Operation: wc (Word Count) Usage Examples

Recommended

Oracle VirtualBox: Port Forwarding in NAT Network Mode

Oracle VirtualBox: Port Forwarding in NAT Network Mode

Install SoftEther VPN Server on Ubuntu 24.04

Install SoftEther VPN Server on Ubuntu 24.04

Install Portainer on Ubuntu 24.04 Using Docker Compose

Install Portainer on Ubuntu 24.04 Using Docker Compose

FortiGate Country Address Object Generator – Block or Allow Access by Country

FortiGate Country Address Object Generator – Block or Allow Access by Country

View & Copy Image Metadata Online – Camera & GPS Info

View & Copy Image Metadata Online – Camera & GPS Info

Categories

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos
  • Web Tools
ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Recent News

Install Portainer on Ubuntu 24.04 Using Docker Compose

Install Portainer on Ubuntu 24.04 Using Docker Compose

FortiGate Country Address Object Generator – Block or Allow Access by Country

FortiGate Country Address Object Generator – Block or Allow Access by Country

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
    • Bash Scripts
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
  • Web Tools

© 2025 defencedev.com - All rights reserved.