#!/bin/bash # By Malcolm Strydom # ivtv@lds.dyndns.org # 3/12/2004 # # Version 0.01 # # This script will check if your ivtv driver for your # PVR-350 or PVR-250 has loaded correctly. # If it can't get any data from /dev/video0 or /dev/video1 # and so on it will reboot the machine until it does. # # The last part of the script starts up lircd and mythbackend. # Modify to match your setup or leave commented out if you # prefer to do it your own way. # # This script assumes you have two capture cards but is very # easy to change for one or three or more cards. # See comments in script to modify specifically for one PVR card. # # You can set a max number of reboots to prevent an endless loop. # Default is 3 reboots. # It keeps a log file and emails you when it's forced to reboot the box. # # Since the script will be run as root from the init scripts at boot I use # "su -c" through out so testing is done as your myth user. # User defined variables user=mythtv # This is the user video/myth related commands will be executed as log=/home/$user/log.pvr # Log file file0=/tmp/test0.mpg # Where to write 3 second test file. First PVR file1=/tmp/test1.mpg # Where to write 3 second test file. Second PVR rebootflag=/home/$user/reboot-flag.txt # File to keep count of reboots numreboot=3 # Number of reboots you will allow before it gives up email=you@domain.org # Where to email errors and logs # End user defined variables su -c "/bin/cat /dev/video0 > $file0 &" $user sleep 3 su -c "kill `ps -ef|grep /dev/video0 | grep -v grep | awk {'print $2'}`" $user # Comment out the next 3 lines if you only have one PVR card su -c "/bin/cat /dev/video1 > $file1 &" $user sleep 3 su -c "kill `ps -ef|grep /dev/video1 | grep -v grep | awk {'print $2'}`" $user test0=`ls -l $file0 | awk {'print $5'}` # Comment out the next line if you only have one PVR card test1=`ls -l $file1 | awk {'print $5'}` rf=`cat $rebootflag` # Comment out the next line and uncomment the following line if you only have one PVR card if [ $test0 == 0 ] || [ $test1 == 0 ] # if [ $test0 == 0 ] then echo `date` "PVR 1 /dev/video0 file size $test0" >> $log echo `date` "PVR 2 /dev/video1 file size $test1" >> $log # Comment out for 1 PVR card if [ $rf -ge $numreboot ] then echo `date` "To many reboots. Starting Myth anyway." >> $log mail -s "Box has rebooted 3 times and still has a problem" $email < $log boot='yes' echo "0" > $rebootflag else echo `date` "0 byte recording - rebooting box" >> $log let "rf=($rf + 1)" echo "$rf" > $rebootflag boot='no' mail -s "Box has to be rebooted" $email < $log sleep 2 # Delay so email can leave your box reboot fi else boot='yes' echo "0" > $rebootflag # resets reboot flag echo `date` "No reboot required." >> $log fi if [ $boot = 'yes' ] then echo `date` "Starting lircd" >> $log /usr/local/sbin/lircd echo `date` "Starting MythTV backend" >> $log su -c "/usr/local/bin/mythbackend -d -l /home/$user/log.back" $user echo `date` "Flagging unflagged recordings for commercials" >> $log su -c "sleep 30 && /usr/local/bin/mythcommflag --force" $user fi