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

Solution: CPU Temperature Monitoring on Raspberry Pi4

neo by neo
May 27, 2025
in Solutions
0
Solution: CPU Temperature Monitoring on Raspberry Pi4

Solution: CPU Temperature Monitoring on Raspberry Pi4

0
SHARES
14
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

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.

ADVERTISEMENT

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

Solution: Ubuntu Internet Connection Monitoring Script (Create a Log File, Possible to Send per Email)

Next Post

Linux Files Operation: wc (Word Count) Usage Examples

neo

neo

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

Linux Files Operation: wc (Word Count) Usage Examples

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

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

Browse by Category

  • 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

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

  • 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
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.