Comment 10 for bug 229797

Revision history for this message
edvale (edvale) wrote :

No I don't mind sharing the script at all. I start it from /etc/rc.local with nohup. I hacked it together in a few minutes, so it isn't pretty, but here goes:

#!/bin/bash

MYLOGFILE="/root/mythtvBugCheck.log"

MYTHLOGFILNAME="mythbackend.log"
MYTHLOGDIRNAME="/var/log/mythtv/"

OK_STRING="All is well"
MARK_STRING="-- MARK --"
BUGG_STRING="Warning: Recording will not commence until a PMT is set"

typeset -i cnt=0
typeset -i CNT_MAX=60

while (true)
do
   cnt=`expr $cnt + 1`

   grep "$BUGG_STRING" ${MYTHLOGDIRNAME}${MYTHLOGFILNAME} >/dev/null

   if [[ $? -eq 0 ]]; then
      echo "`date '+%Y-%m-%d %H:%M:%S'`: Restart MythTV backend..." >> $MYLOGFILE
      /etc/init.d/mythtv-backend stop >> $MYLOGFILE 2>> $MYLOGFILE
      cp -p ${MYTHLOGDIRNAME}${MYTHLOGFILNAME} /tmp
      grep -v "$BUGG_STRING" /tmp/${MYTHLOGFILNAME} > ${MYTHLOGDIRNAME}${MYTHLOGFILNAME}
      /etc/init.d/mythtv-backend start >> $MYLOGFILE 2>> $MYLOGFILE
   else
      if [[ $cnt -ge $CNT_MAX ]]; then
         cnt=0
         grep -v "$OK_STRING" $MYLOGFILE > ${MYLOGFILE}.$$
         echo "`date '+%Y-%m-%d %H:%M:%S'`: $MARK_STRING" >> ${MYLOGFILE}.$$
         mv ${MYLOGFILE}.$$ $MYLOGFILE
      else
         echo "`date '+%Y-%m-%d %H:%M:%S'`: ${OK_STRING}" >> $MYLOGFILE
      fi
   fi

   sleep 60

done