Monday, October 06, 2008

mc2xml on ubuntu

I recently switched to mc2xml for grabbing TV listings from TitanTV. The service doesn't always respond in a timely manner and so I needed a script to retry a couple of times in case it failed the first time. Here is the bash script that I wrote to retry every 60 seconds for 15 minutes. I hope that it helps someone else.

#!/bin/bash

servicebusy=2
repeats=0
maxrepeats=15

cd /home/user/mc2xml
./mc2xml
errorcode=$?

echo Error Code == $errorcode

while [[ $errorcode -eq $servicebusy ]]; do
if [[ $repeats -ge $maxrepeats ]]; then
exit -1
fi
let "repeats += 1"
echo repeating in 60 seconds \( try $repeats of $maxrepeats \)
sleep 60
./mc2xml
errorcode=$?
done

mythfilldatabase --refresh-all --file 1 xmltv.xml
I run it every night with the following command in my crontab

39 2 * * 1-7 bash /home/user/mc2xml/do_mythfill_fixed.sh

 

Blogger Template by Blogcrowds