I was thinking, oh this is no problem just add one line so it sends an email.
BUT this was a little bit more complicated.
Because if the temp is at the $HIGH warning point, it sleeps 2 seconds and
the goes on again. If I just put a mail command there it sends a mail every
few seconds, probably not so good LOL.
So I made a timestamp and check if it sent mail in the last 5 minutes
(found that here:
http://stackoverflow.com/questions/205666/what-is-the-best-way-to-perform-timestamp-comparison-in-bash)
And how to make it send the ok temps every hour? I now made it log the temps
to a file, so you can make a cronjob that mails it to you every hour (/tmp/temp.log).
Also I think this script had a bug, the shutdown stuff never executed because
even if you reach $SHUTDOWN_TEMP, the temp is higher then the $HIGH temp
and so it never went into the else loop. Moved that shutdown stuff at the beginning now,
so it gets checked first. But I probably created more bugs now haha
You can start the script with a $ at the end, so it keeps running in the background.
Maybe you have a startup script for your miners, then you can just add it at the end.
#!/bin/sh
CARDS="0 1 2 3 4 5"
HIGH=70
SHUTDOWN_TEMP=85
TDAT="/tmp/temp.dat"
TLOG="/tmp/temp.log"
MAILTO="dude@somewhere.org"
while true
do
for card in $CARDS; do
# read temp
TEMP=$(DISPLAY=:0 aticonfig --adapter=$card --odgt |grep 'Sensor'|awk -F\ '{ print $5 }'|cut -d. -f1)
if [ "$TEMP" -gt "$SHUTDOWN_TEMP" ];
then
MSG="GPU$card to hot, shutting down in 30 sek.!"
echo "$MSG" | wall
echo "$MSG" | mail -s "warning shutdown temp reached" $MAILTO
sleep 30
sudo shutdown -h now
elif [ "$TEMP" -gt "$HIGH" ];
then
MSG="High temp GPU$card: $TEMP > $HIGH"
echo "$MSG" | tee -a $TDAT | wall
# build a file with a timestamp to compare if mail was
# sent in the last 5 minutes. First fill it with 0 if not
# existant.
if [ ! -f /tmp/.lastmail ]; then
echo "0" > /tmp/.lastmail
fi
last=$(cat /tmp/.lastmail)
curr=$(date +%s)
# check difference
diff=$(($curr - $last))
# check if diff is greater than 5 minutes
if [ "$diff" -gt 300 ]; then
echo "$MSG" | mail -s "GPU$card high temp warning" $MAILTO
# write timestamp
echo "$curr" >/tmp/.lastmail
else
echo "not sending mail, waiting to reach time limit."
fi
sleep 2
else
echo gpu$card temp OK: $TEMP | tee -a $TDAT
sleep 5
fi
done
# end of for loop, move temp file so it can be mailed by cron
mv $TDAT $TLOG
done