#!/bin/ksh maxtemp=30 #maxtemp=32 hour=`date +%Y-%m-%d-%H` second=`date +%H:%M:%S` bomb() { echo error: $@ exit 1 } alarm() { if [[ -f /var/tmp/alert-cpu-temperature-$hour.lock ]]; then echo $temp >> /var/tmp/alert-cpu-temperature-$hour.lock else echo $temp > /var/tmp/alert-cpu-temperature-$hour.lock echo cpu temperature $temp above threshold $maxtemp fi } clear_alarm() { if [[ -f /var/tmp/alert-cpu-temperature-$hour.lock ]]; then echo cpu temperature back to normal: $temp mv -f /var/tmp/alert-cpu-temperature-$hour.lock /var/tmp/alert-cpu-temperature-$second.lock.disabled fi } float temp=`sensors | grep ^Tctl: | awk '{print $2}' | sed -r 's/\+([[:digit:]\.]+).*/\1/'` [[ -z $temp ]] && bomb could not evaluate cpu temperature - \$temp is empty if (( temp >= maxtemp )); then alarm else clear_alarm fi