2012-09-22, 17:15
Hi,
I am writing a script to shut down XBMC in case it is idling overnight (my son often plays with the remote and starts it without anybody noticing). Since the box it runs on is powered on 24/7, I wanted to prevent CPU cycles going to waste (XBMC running consumes an additional 7W, actually).
Anyway, I am using a "quick and dirty" shell script trigerred by a cron tab (see below). The script checks if music or video is playing and if not, shuts it down. I would like to use a more robust check, and in particular, only shut down XBMC if it is idle (screensaver on). I have unfortunately not found anything in the JSONRPC api that would do that.
Does anybody have oter ideas?
I am writing a script to shut down XBMC in case it is idling overnight (my son often plays with the remote and starts it without anybody noticing). Since the box it runs on is powered on 24/7, I wanted to prevent CPU cycles going to waste (XBMC running consumes an additional 7W, actually).
Anyway, I am using a "quick and dirty" shell script trigerred by a cron tab (see below). The script checks if music or video is playing and if not, shuts it down. I would like to use a more robust check, and in particular, only shut down XBMC if it is idle (screensaver on). I have unfortunately not found anything in the JSONRPC api that would do that.
Does anybody have oter ideas?
Code:
#!/bin/bash
LOG=/tmp/xbmc-watch.log
# Test to see if XBMC is running first
if pidof xbmc.bin
then
# XBMC is running
curl -s -o /tmp/xbmc-video -u xbmc:xbmc -X POST -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": {"playerid":1 }, "id": 1}' http://localhost:8080/jsonrpc
curl -s -o /tmp/xbmc-audio -u xbmc:xbmc -X POST -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": {"playerid":0 }, "id": 1}' http://localhost:8080/jsonrpc
grep -w "error" /tmp/xbmc-video >/dev/null
if [ $? -eq 0 ]
then
grep -w "error" /tmp/xbmc-audio >/dev/null
if [ $? -eq 0 ]
then
#XBMC idling, let's shut it down
pidof xbmc.bin xargs kill #graceful shutdown
echo `date` "XBMC-watch killed XBMC (soft)" >> $LOG
sleep 2
if pidof xbmc.bin
then
pidof xbmc.bin|xargs kill -9
echo `date` "XBMC-watch killed XBMC (hard)" >> $LOG
fi
else
echo `date` "XBMC plating audio" >> $LOG
fi
else
echo `date` "XBMC plating video" >> $LOG
fi
else
echo `date` "XBMC not running" >> $LOG
fi