Hi,
The above is a beautiful test case. It captures exactly the situation. Let me know whether you'd like me to test anything more.
btw, I wrote the following hack (yes, it's a hack!)which, when run via cron will check whether my phone is eating battery or not. Once it detects your phone is eating battery, it'll stop chimping at you until the condition clears. At which point, it'll send you a message saying all is well.
To configure, set:
- PHONE_HOSTNAME_OR_IP - the hostname or IP of your phone.
- WHOM_TO_NOTIFY - the email address to mail the event. I have mine set to mail me a text page.
Code:
#!/bin/bash
PHONE_HOSTNAME_OR_IP=clucker
WHOM_TO_NOTIFY="send-me-a-text-page@example.com"
RESULTS=`ping -c 5 $PHONE_HOSTNAME_OR_IP | sed -n '/transmitt/,/rtt/p'`
NOTIFY_HISTORY=/var/tmp/.`basename $0`
case $RESULTS in
*transmitted*)
RCVD=`echo $RESULTS | sed 's/^.*transmitted, //g' | awk '{ print $1 }'`
if [ -n "$RCVD" -a $RCVD -ge 1 ] ; then
AVG_PING_TIME=`echo $RESULTS | sed 's/^.*mdev = //g' | cut -d'/' -f2`
if [ -n "$AVG_PING_TIME" ] ; then
#
# Strip away decimals
#
AVG_PING_TIME=`echo $AVG_PING_TIME | sed 's/[.][0-9]*//'`
#
# Do we need to raise an alarm?
#
if [ $AVG_PING_TIME -lt 10 -a ! -f $NOTIFY_HISTORY ] ; then
Mail -s "Phone burning battery ..." $WHOM_TO_NOTIFY < /dev/null
touch $NOTIFY_HISTORY
#
# All is well ... :)
#
elif [ $AVG_PING_TIME -ge 10 -a -f $NOTIFY_HISTORY ] ; then
Mail -s "Phone is well" $WHOM_TO_NOTIFY < /dev/null
rm -f $NOTIFY_HISTORY
fi
fi
else
rm -f $NOTIFY_HISTORY
fi
;;
esac