I am having problems with the mythbackend stalling on me and I wanted to monitor and restat when neccessary. I Googled around ang found a script made by David A. Mason (damason at redshift.com)

I took these and modified them a bit.

Myth lock present but service not running:
================
#!/bin/sh

if test -f /var/lock/subsys/mythbackend ; then
echo “Myth subsys set”
running=`eval ps aux | grep mythback | grep -v grep | wc -l | awk ‘{
print $1 }’`
if [ $running -eq “0″ ] ; then
echo “*** Error: mythbackend found stopped at `date` ***”
>>/var/log/mythbackend.log
rmmod -r ivtv msp3400 saa7115
modprobe ivtv
/etc/rc.d/init.d/mythbackend restart
echo “*** mythbackend restarted at `date` ***”
>>/var/log/mythbackend.log
fi
fi
================

and Myth/ivtv producing zero-length files:
================
#!/bin/sh

if test -f /var/lock/subsys/mythbackend ; then
echo “Myth subsys set”
NOW=`date ‘+%b %e %R’`
ZEROS = `eval ls -l /var/video/record/*nuv | grep ” 0 $NOW” | wc -l
| awk ‘{ print $1 }’`
if [ $ZEROS -ne “0″ ] ; then
echo “*** Error: mythbackend making zero-length files at
`date` ***” >>/var/log/mythbackend.log
rmmod -r ivtv msp3400 saa7115
modprobe ivtv
/etc/rc.d/init.d/mythbackend restart
echo “*** mythbackend restarted at `date` ***”
>>/var/log/mythbackend.log
fi
fi
================

The latter hasn’t really been tested much, but I’m about to schedule it. It
might be necessary to tell it to reboot rather than just reloading the
driver and mythbackend, however.

One further caveat is that I have modified the mythbackend rc script to
delete its lockfile on stop and restart:
================
stop() {
echo -n “Stopping ${MBE_PROG}: ”
killproc ${MBE_LOCATION}${MBE_PROG}
rm -f /var/lock/subsys/${MBE_PROG}
echo
return $RETVAL
}
================