[mythtv-users] Auto poweroff an idle front-end?

Michelle Dupuis mdupuis at ocg.ca
Tue Apr 9 16:22:01 UTC 2013


Ok...I've got something working.  For anyone else interested, I've attached my bash script below.  Just add to cron at whatever frequency you like (the shorter the interval the more certainty you aren't shutting down while a viewer is still present)!

#!/bin/bash
# How long must be idle until shutdown
shutdownmin=5
# Shutdown command
# shutdowncmd="shutdown -h 0"
shutdowncmd="echo shutdown!"
# Temp file to track idle time
idlefile=/tmp/mythfeidle
#---Don't touch below here unless you know what you are doing!
if [ ! -f $idlefile ] ; then
  touch $idlefile
fi
NOW=$(date +%s)
OLD=$(stat -c %Z $idlefile)
DIFF=$(((NOW-OLD)/60))
COUNTDOWN=$(($shutdownmin-$DIFF))
if [ $COUNTDOWN -lt 1 ] ; then
  COUNTDOWN=0
fi
state=$(curl http://localhost:6547/Frontend/GetStatus 2>1)
state=$(echo $state | awk 'BEGIN { FS = "<Key>state</Key>" } { print $2 }')
state=$(echo $state | awk 'BEGIN { FS = "</Value>" } { print $1 }')
state=$(echo $state | awk 'BEGIN { FS = "<Value>" } { print $2 }')
if [ "$state" == "idle" ] ; then
  echo "Idle for $DIFF minutes, shutdown in $COUNTDOWN minutes"
else
#  rm -f $idlefile
  echo "Not idle"
fi
#echo "NOW: $NOW, OLD: $OLD, DIFF: $DIFF"
if [ $COUNTDOWN -eq 0 ] ; then
  $shutdowncmd
fi


More information about the mythtv-users mailing list