Hi All,
I didn't like the current wakeup test (knoppmyth-wakeuptest.pl) at the KnoppMythWiki as it didn't take into account the user wakeup periods for performing system tasks etc. I wrote some dodgy code that checks the values stored by NVRAM_WAKEUP and if it is within 10 minutes of the current time then an automated powerup must have been performed.
The routine looks for particular paterns returned by NVRAM_WAKEUP to gather day, hour, minutes and converts everything to minutes since the start of the month, accordingly it will not perform to well at the roll over time at midnight at the end of the month.
PS.
To everyone who has contributed to Knoppmyth and Mythtv, Thank you.
Code:
#!/bin/bash
#Alternative method for checking reason for powerup.
#Checks values stored in NVRAM_WAKEUP and if within 10 minutes,
#then must be due to automated processes.
#DESIGN LIMITATION
#Doesn't handle time period around midnight of last night of month
#Enjoy
#BigB
#Get time stored in NVRAM
NVRAM_DAY="`sudo nvram-wakeup |awk '$1=="Day" { print $3 }'`"
NVRAM_HOUR="`sudo nvram-wakeup |awk '$1=="rtcHour" { print $3 }'`"
NVRAM_MIN="`sudo nvram-wakeup |awk '$1=="rtcMin" { print $3 }'`"
#echo "$NVRAM_DAY $NVRAM_HOUR $NVRAM_MIN"
let "NVRAM_TIME = NVRAM_DAY*24*60 + NVRAM_HOUR*60 + NVRAM_MIN"
#Get current date (remove '-u' option for non utc time)
DATE="`date -u +%e%t%H%t%M`"
#parse Date
NOW_DAY="`echo $DATE|awk '{ print $1 }'`"
NOW_HOUR="`echo $DATE|awk '{ print $2 }'`"
NOW_MIN="`echo $DATE|awk '{ print $3 }'`"
#echo "$NOW_DAY $NOW_HOUR $NOW_MIN"
let "NOW_TIME = NOW_DAY*24*60 + NOW_HOUR*60 + NOW_MIN"
#Time 10 minuts ago
let "THEN_TIME = NOW_TIME - 10"
if [ "$NVRAM_TIME" -ge "$THEN_TIME" ]; then
if [ "$NVRAM_TIME" -le "$NOW_TIME" ]; then
echo "Automated wakeup, killing Mythfrontend"
sleep 30
killall mythfrontend
else
echo "Automated wakeup is in future"
fi
else
echo "Automated wakeup in in past"
fi