<br><div class="gmail_quote">On 5 October 2011 18:10, David Moore <span dir="ltr"><<a href="mailto:dmoo1790@ihug.co.nz">dmoo1790@ihug.co.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 05/10/11 17:35, Jason Taylor wrote:<br>
> Some people like to leave their systems on 24/7 but I like to save the<br>
> planet :) so I have mine set up to power down after I log off and power<br>
> up again when myth needs to record something.<br>
><br>
><br>
> I've never manager to get this working as I'd like.. basically if its<br>
</div>> after say 10pm and nothing is /being recorded or played/ I'd like the<br>
<div class="im">> machine to shutdown and then always wake up at say 8am (or earlier if<br>
> required for a recording).. this would save 10 hours of ontime a day and<br>
> keep the mrs happy about having to start the machine...<br>
><br>
> I should really have another attempt at it... it would be quite a power<br>
> saving...<br>
><br>
</div>It wasn't too hard once I got my head around UTC vs NZ time zone stuff.<br>
I started with this web page:<br>
<br>
<a href="http://www.mythtv.org/wiki/ACPI_Wakeup" target="_blank">http://www.mythtv.org/wiki/ACPI_Wakeup</a><br>
<br>
Then I modified the setwakeup.sh script to suit my system and always<br>
wake at 6 pm (or earlier if needed to record) and power down at or after<br>
10:30 pm if nobody is logged in. Here's the script I'm using now:<br>
<br>
---------------------------------------------------------------<br>
#!/bin/sh<br>
#<br>
# set ACPI Wakeup time<br>
# usage: setwakeup.sh seconds<br>
# seconds - number of seconds from epoch to UTC time (time_t time format)<br>
#<br>
# set UTCBIOS to true if bios is using UTC time<br>
# set UTCBIOS to false if bios is using local time<br>
<br>
UTCBIOS=false<br>
<br>
ONTIME=`date -u --date "\`date --date 'TZ="Pacific/Auckland" 6:00 pm<br>
today' +%F" "%T\`" +%s`<br>
ONNEXT=`date -u --date "\`date --date 'TZ="Pacific/Auckland" 6:00 pm<br>
tomorrow' +%F" "%T\`" +%s`<br>
OFFTIME=`date -u --date "\`date --date 'TZ="Pacific/Auckland" 10:30 pm<br>
today' +%F" "%T\`" +%s`<br>
NOW=`date -u --date "\`date +%F" "%T\`" +%s`<br>
<br>
echo $ONTIME<br>
echo $OFFTIME<br>
echo $ONNEXT<br>
echo $NOW<br>
<br>
if $UTCBIOS<br>
then<br>
#utc bios - use supplied seconds<br>
SECS=$1<br>
else<br>
#non utc bios - convert supplied seconds to seconds from<br>
#epoch to local time<br>
SECS=`date -u --date "\`date --date @$1 +%F" "%T\`" +%s`<br>
<br>
echo $SECS<br>
<br>
if [ $NOW -lt $ONTIME ]; then<br>
if [ $SECS -gt $ONTIME ]; then<br>
SECS=$ONTIME<br>
echo "on time "$SECS<br>
fi<br>
else<br>
if [ $SECS -gt $ONNEXT ]; then<br>
SECS=$ONNEXT<br>
echo "on next "$SECS<br>
fi<br>
fi<br>
fi<br>
<br>
echo 0 > /sys/class/rtc/rtc0/wakealarm #this clears your alarm.<br>
echo $SECS > /sys/class/rtc/rtc0/wakealarm #this writes your alarm<br>
<br>
cat /proc/driver/rtc #check if alarm set<br>
---------------------------------------------------------------<br>
<br>
Here's my checklogin.sh script:<br>
<br>
---------------------------------------------------------------<br>
#!/bin/bash<br>
# Check to see if anyone is currently logged in. Return zero if not and<br>
1 if so.<br>
# Echoed text appears in log file. It can be removed and --quiet added<br>
to the<br>
# grep command once you are satisfied that mythTV is working properly<br>
<br>
ONTIME=`date --date "6:00 pm today" +%s`<br>
OFFTIME=`date --date "10:30 pm today" +%s`<br>
NOW=`date +%s`<br>
<br>
#DATE=`date +%F\ %T\.%N`<br>
#DATE=${DATE:0:23}<br>
if<br>
# The leading space is important!<br>
w | grep --quiet " 0 users"<br>
then<br>
# echo $DATE Noone is logged in, ok to shut down.<br>
if [ $NOW -ge $OFFTIME -o $NOW -lt $ONTIME ]; then<br>
exit 0<br>
else<br>
exit 1<br>
fi<br>
else<br>
# echo $DATE Someone is still logged in, don\'t shut down!<br>
exit 1<br>
fi<br></blockquote><div><br>Thanks for that... the biggest issue I have is the system is never logged out, but thats a great starting point<br><br>I know the wakeup works after playing with the rtc scripts its just getting the shutdown and wakeups to do what i want<br>
<br clear="all"></div></div>-- <br>"Weekends don't count unless you spend them doing something completely pointless. " - Calven<br><br>