Skip to content

Instantly share code, notes, and snippets.

@potados99
Created October 9, 2025 06:29
Show Gist options
  • Save potados99/47be8d7afef20aa92ffdd6a42ed0d61f to your computer and use it in GitHub Desktop.
Save potados99/47be8d7afef20aa92ffdd6a42ed0d61f to your computer and use it in GitHub Desktop.
Raspberry Pi system status monitoring script
#!/bin/bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Get CPU usage (quick method using top)
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)
if [ -z "$CPU" ]; then
# Fallback for different top output format
CPU=$(top -bn1 | grep "%Cpu" | awk '{print $2}' | cut -d'%' -f1)
fi
# Get Memory usage
MEM=$(free | grep Mem | awk '{printf "%.1f", ($3/$2) * 100}')
MEM_USED=$(free -h | grep Mem | awk '{print $3}')
MEM_TOTAL=$(free -h | grep Mem | awk '{print $2}')
# Get Temperature
if [ -f /sys/class/thermal/thermal_zone0/temp ]; then
TEMP=$(awk '{printf "%.1f", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
else
TEMP="N/A"
fi
# Color coding for temperature
TEMP_COLOR=$GREEN
if [ "$TEMP" != "N/A" ]; then
TEMP_INT=${TEMP%.*}
if [ "$TEMP_INT" -ge 80 ]; then
TEMP_COLOR=$RED
elif [ "$TEMP_INT" -ge 70 ]; then
TEMP_COLOR=$YELLOW
fi
fi
# Color coding for CPU
CPU_COLOR=$GREEN
CPU_INT=${CPU%.*}
if [ "$CPU_INT" -ge 80 ]; then
CPU_COLOR=$RED
elif [ "$CPU_INT" -ge 50 ]; then
CPU_COLOR=$YELLOW
fi
# Color coding for Memory
MEM_COLOR=$GREEN
MEM_INT=${MEM%.*}
if [ "$MEM_INT" -ge 90 ]; then
MEM_COLOR=$RED
elif [ "$MEM_INT" -ge 70 ]; then
MEM_COLOR=$YELLOW
fi
# Output
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN}${BOLD}CPU${NC} ${CPU_COLOR}${CPU}%${NC}"
echo -e "${MAGENTA}${BOLD}MEM${NC} ${MEM_COLOR}${MEM}%${NC} ${BLUE}(${MEM_USED}/${MEM_TOTAL})${NC}"
echo -e "${YELLOW}${BOLD}TMP${NC} ${TEMP_COLOR}${TEMP}°C${NC}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment