Last active
January 10, 2024 19:06
-
-
Save jasonhejna/c75995cf2c2648d6030e5565e280feaa to your computer and use it in GitHub Desktop.
cpu_temp_log.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# File to store the CPU temperature logs | |
LOG_FILE="cpu_temp_log.csv" | |
# Function to get CPU temperature | |
get_cpu_temp() { | |
# Using sensors command to get CPU temp from the specified sensor | |
sensors | grep 'temp1:' | awk '{print $2}' | tr -d '+C' | |
} | |
# Create CSV file and add header if it doesn't exist | |
if [ ! -f "$LOG_FILE" ]; then | |
echo "Timestamp,CPU Temperature (°C)" > "$LOG_FILE" | |
fi | |
# Infinite loop to monitor temperature every 30 seconds | |
while true | |
do | |
# Get current Unix timestamp | |
TIMESTAMP=$(date '+%s') | |
# Get CPU temperature | |
TEMP=$(get_cpu_temp) | |
# Save to file in CSV format | |
echo "$TIMESTAMP,$TEMP" >> "$LOG_FILE" | |
# Wait for 30 seconds | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment