ahoffmann's script misses one of your requirements - that it only sends a mail when "there's a change from the last value". As it is it will continue to email you once a minute until the temperature drops.
You can add the following below the "echo" statement to add that requirement :
[ $temp -eq $last_temp ] && exit
The 2nd last line is also wrong - it's using a -o (or) where it should be and, plus it's using $last rather than $last_temp. I'd replace this line with :
[ $temp -le 20 ] && [ $last_temp -ge 21 ] && mail -slast21+ me@some.where
Main Topics
Browse All Topics





by: ahoffmannPosted on 2009-05-09 at 07:38:11ID: 24343987
#! /bin/sh
last_temp=0
last=/tmp/last_temp
[ -e $last ] && last_temp=`cat $last`
temp=`prtdiag -v |awk '/AMBIENT/{print $2}'`
echo $tmp >$last
[ $temp -ge 21 ] && mail -s21+ me@some.where
[ $temp -le 20 -o $last -ge 21 ] && mail -slast21+ me@some.where
exit 0
# not that the script relies on your cron to satisify your "one minute ago" condition