Sunday, December 04, 2005

Save power.

One thing that I noticed in the installation of 0.18.1 of MythTV is that the detection of whether the computer was started automatically or not no longer worked for me. I used to have this script fire up the frontend for me:

mythtv@mythtv ~ $ cat /usr/local/bin/mythguictrl
#!/usr/bin/perl

use warnings;
use strict;

package main;


my $lockfile ='/home/mythtv/.mythguilock';
my $logfile ='/home/mythtv/.mythtv/guilocklog';

my $date =`/usr/bin/date`;

-e $lockfile and unlink $lockfile;

if( $ARGV[0] eq "auto" ){

open LOCK,'>',$lockfile;
print LOCK "1";
close LOCK;

}


open(STARTLOG,">> $logfile ") or die "Unable to open log file:$!";
print STARTLOG "$ARGV[0] $date";
close(STARTLOG);

1;


This script is iserted as a startup script of MythTV. If the computer was started up automatically, for instance using nwram-startup, it is supplied the argument 'auto', the frontend was not started, and the box would shut down itself after recording was done.

Now, after 0.18.1, this did not work anymore, so we started using more power than necessary since the box would fire up, record and then be on for the rest of the day. Not good.

An alternative solution was posted by Phill Edwards here

mythtv@mythtv ~ $ cat /home/mythtv/bin/remote_chk.sh
#!/bin/bash
#
# remote_chk.sh
# This script checks whether any keys have been pressed on the remote control
# in the TIMEOUT seconds since mythfrontend was started (this script is started
# when mythfrontend is from .ratpoisonrc). If there has been any presses then
# the frontend is assumed to be in use and so we don't want to shutdown
# mythfrontend. If there haven't been any key presses then assume that it's not
# in use so we kill mythfrontend (which is auto started on system startup) so
# that the auto shutdown processing can then go ahead.


PROG=mythfrontend
#15 minutes
TIMEOUT=900
LOGF=/home/mythtv/.mythtv/irw.log

irw > $LOGF &
sleep $TIMEOUT

IRLOG=`cat $LOGF | wc -l | awk '{print $1}'`
#UNK=`cat $LOGF | grep unknown | grep -v grep | wc -l | awk '{print $1}'`

#if [ $IRLOG -eq 0 ] || [ $IRLOG == $UNK ]

if [ $IRLOG -eq 0 ]
then
echo "remote_chk.sh killing mythfrontend at `date`" >> /tmp/mythrestart.log
killall $PROG
fi

exit 0

This script will shut down the frontend after 20 minutes if no button on the remote control has been pressed before this time. Since human use of MythTV requires at least one menu change, this will prevent it from shuting down the box in case you acctually wanted to use it from the frontend. Inventive work-around.