Script: Monitoring CPU Temperatur unter Debian

Folgendes Script ermöglicht die Benachrichtigung per Mail bei überschrittener Temperaturschwelle ( basiert auf LM-Sensors ).


#!/bin/bash

# Email an alert should be sent to in the event the reading exceeds the trigger
 email=MAIL@MAILADDRESS.COM
 # Trigger amount in Celsuis
 temp_triggerCPU=65
 temp_triggerMB=55
 # Extract the reading of our desired sensor using the 'sensors' command
 tempCPU=$(sensors|grep 'Core0 Temp:' | awk '{print $3}' | cut -b2,3,4,5)
 tempMB=$(sensors|grep 'Core1 Temp:' | awk '{print $3}' | cut -b2,3,4,5)
 # Round our temperature reading to the nearest whole number
 rounded_tempCPU=$(echo $tempCPU | awk '{printf("%d\n",$1 + 0.5)}')
 rounded_tempMB=$(echo $tempMB | awk '{printf("%d\n",$1 + 0.5)}')
 # Compare the temperature reading with our alert trigger
 if [ $rounded_tempCPU -ge $temp_triggerCPU ]; then
 # Send an email alerting the admin!
 echo "Temperatur der CPU ist $tempCPU Celsius" | mailx -s "Xen-Server Temperatur warnung" $email
 else
 if [ $rounded_tempMB -ge $temp_triggerMB ]; then
 # Send an email alerting the admin!
 echo "Temperatur des MB ist $tempMB Celsius" | mailx -s "Xen-Server Temperatur warnung" $email
 else
 echo >> /dev/null
 fi
 fi