#!/bin/sh # temperature_alert.sh # relies on lm_sensors being installed # On my systems this runs as a cron job # Meryll Larkin September 2013 # refactored array, output choices July 2020 # August 2021 added "screen_view" variable so screen output could be turned off toohot=95 # toohot=60 # for testing purposes # screen_view : send output to screen yes = 1 no = 0 screen_view=0 # do you want to send email? y = 1 no = 0 sendemail=0 # separate each email address by a space mailto='bogus@bogus.com sugob@bogus.net' # makelog do you want to create log to keep on server ? yes = 1 no = 0 makelog=1 server=`hostname` if [ $makelog -gt 0 ] ; then mkdir -p /root/bin/LOG fi datestring=$(date +"%Y%m%d") hrMin=$(date +"%H:%M") if [ $makelog -gt 0 ] ; then LOG=/root/bin/LOG/temp_${datestring}.log # prune logs more than 1 month old for space considerations find /root/bin/LOG/ -type f -mtime +31 -name 'temp_*' -exec rm {} \; fi tmp_array=`/usr/bin/sensors -f |grep 'temp'| awk '{print $2}'| tr -d '+' | tr -d '°F'` IFS=$'\n' sorted=($(sort <<<"${tmp_array[*]}")) unset IFS # printf "[%s]\n" "${sorted[@]}" highest=`echo ${sorted[-1]}` # echo "highest = $highest" if (( $(echo "$highest > $toohot" | bc -l) )); then subject="$server is at $highest degrees F" message=`/usr/bin/sensors -f` if [ $makelog -gt 0 ] ; then echo "$datestring $hrMin $server reports temperature of $highest degrees F" >>$LOG /usr/bin/sensors -f >> $LOG echo "" >> $LOG fi if [ $screen_view -gt 0 ] ; then echo "$datestring $hrMin $server reports temperature of $highest degrees F" /usr/bin/sensors -f fi if [ $sendemail -gt 0 ] ; then if [ $screen_view -gt 0 ] ; then echo "Found temperature of $highest, sending email" fi echo "$message" | mail -s "$subject" $mailto fi fi exit