[mythtv-users] Checking for zero byte recordings

Kevin Kuphal kuphal at dls.net
Fri Jun 23 02:18:31 UTC 2006


Since it sometimes happens that a recording is aborted (zero byte) due 
to some problem, I've tried writing a little script to detect this in 
the logs and report it to me.

1.  Detection in SQL.  This SQL (stored for me as bad_rec_check.sql) 
finds all rows that start with the same string in the details (namely, 
the same "Started/Finished" text) and then counts the occurrences that 
matched to the second, namely a Started Recording immediately followed 
by Finished recording.  It seems fairly accurate.  It also acknowledges 
those items that it has checked so it doesn't keep emailing over and over.

SELECT logdate, COUNT( logdate ) AS NumOccurances, message
FROM mythlog
WHERE message
LIKE  '%Recording%' AND acknowledged = 0
GROUP BY LEFT( details, LOCATE( ':', details )-1 ), logdate
HAVING COUNT( logdate ) > 1;

UPDATE mythlog SET acknowledged = 1 WHERE message LIKE '%Recording%';

2.  Running the SQL.  I use a simple backend-rec-check.sh script to 
test, run on 0,1 and 30,31 on the hour in my crontab.  It simply runs 
another script if the count of bad recordings is greater than zero.

mysql -u username --password=password -D mythconverg < bad_rec_check.sql 
| grep -c '-' | awk '{if ($1 > 0) system("~/backend-down.sh");'}

3.  The backend-down.sh script simply sends me an email alerting me to 
the situation.

I've only been using it for a short time, but I think I got the script 
right.  Anyways, I hope this helps someone.  I'll probably add it to the 
wiki if no glaring errors come up.

Kevin


More information about the mythtv-users mailing list