• Contact
  • About Me
  • Privacy Policy
  • Disclaimer
DefenceDev
  • Home
  • Linux
    • Bash Scripting
      • Bash Scripting Lessons
    • Commands&Tips
    • Monitoring
  • Networking
    • FortiGate
    • MikroTik
  • Projects & Case Studies
  • Self-Hosted
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Virtualization
    • Proxmox
    • VMware
  • Tools
No Result
View All Result
  • Home
  • Linux
    • Bash Scripting
      • Bash Scripting Lessons
    • Commands&Tips
    • Monitoring
  • Networking
    • FortiGate
    • MikroTik
  • Projects & Case Studies
  • Self-Hosted
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Virtualization
    • Proxmox
    • VMware
  • Tools
No Result
View All Result
DefenceDev
No Result
View All Result
Home Linux

Solution: CPU Temperature Monitoring on Raspberry Pi

by neo
September 3, 2026
in Linux
0
Solution: CPU Temperature Monitoring on Raspberry Pi4

Solution: CPU Temperature Monitoring on Raspberry Pi4

0
SHARES
54
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:

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:

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

defencedev.com

Previous Post

Fortigate and Ubuntu Bash Automation

Next Post

Linux Files Operation: wc (Word Count) Usage Examples

neo

Related Posts

Get Instant SSH Login Alerts on Ubuntu with Bash and Telegram
Monitoring

Get Instant SSH Login Alerts on Ubuntu with Bash and Telegram

Terminal Colors in Bash: How and When to Use Them
Bash Scripting

Terminal Colors in Bash: How and When to Use Them

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

Ubuntu Internet Connection Monitoring Script: Log Creation and Email Alerts

Free Online Image Tools– Fast, Private, and 100% Browser‑Based
Linux

Free Online Image Tools– Fast, Private, and 100% Browser‑Based

10+ Useful Linux find Command Examples You Should Know
Commands&Tips

10+ Useful Linux find Command Examples You Should Know

Server Reboot with Ansible
Linux

Automating Linux Server Reboot with Ansible

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

Linux Files Operation: wc (Word Count) Usage Examples

Recommended

Nextcloud Access with Multiple Domains – Redirect and SSL Issues (Proxy Manager & Direct Port Forwarding)

Nextcloud Access with Multiple Domains – Redirect and SSL Issues (Proxy Manager & Direct Port Forwarding)

Linux Networking: ping, Troubleshooting Network Connectivity

Linux Networking: ping, Troubleshooting Network Connectivity

Briefly unavailable for scheduled maintenance. Check back in a minute.

WordPress Stuck in Maintenance Mode After Plugin Update

Promox Telegram Alert Example

Configure Telegram Notifications in Proxmox VE Using Webhooks

Fix Proxmox VM Snapshot “Out of Space” Errors

Fix Proxmox VM Snapshot “Out of Space” Errors

Categories

  • Linux
    • Bash Scripting
    • Commands&Tips
    • Monitoring
  • Networking
    • FortiGate
    • MikroTik
  • Projects & Case Studies
  • Self-Hosted
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Virtualization
    • Proxmox
    • VMware
  • Web Tools

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

Briefly unavailable for scheduled maintenance. Check back in a minute.

WordPress Stuck in Maintenance Mode After Plugin Update

Promox Telegram Alert Example

Configure Telegram Notifications in Proxmox VE Using Webhooks

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

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Linux
    • Bash Scripting
      • Bash Scripting Lessons
    • Commands&Tips
    • Monitoring
  • Networking
    • FortiGate
    • MikroTik
  • Projects & Case Studies
  • Self-Hosted
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Virtualization
    • Proxmox
    • VMware
  • Tools

© 2025 defencedev.com - All rights reserved.