macbook-setup/temp-watch.sh

28 lines
966 B
Bash
Raw Normal View History

#!/bin/bash
# temp-watch.sh — Temperaturüberwachung mit Desktop-Notification
# Systemd-Service oder XFCE Autostart
# Warnt bei CPU-Temperatur > THRESHOLD Grad Celsius
THRESHOLD=85
INTERVAL=30
while true; do
TEMP=$(sensors 2>/dev/null | grep -E "Core 0|Package id" | grep -oP '\+\K[0-9.]+' | sort -n | tail -1)
if [[ -n "$TEMP" ]] && (( $(echo "$TEMP > $THRESHOLD" | bc -l) )); then
# Aktuellen Desktop-User ermitteln
DESK_USER=$(who | grep -m1 '(:0)' | awk '{print $1}')
if [[ -n "$DESK_USER" ]]; then
USER_ID=$(id -u "$DESK_USER")
DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/${USER_ID}/bus" \
sudo -u "$DESK_USER" notify-send \
-u critical \
-i dialog-warning \
"🌡 CPU-Temperatur kritisch" \
"${TEMP}°C — Lüfter prüfen!\nmbpfan: $(systemctl is-active mbpfan)"
fi
fi
sleep "$INTERVAL"
done