1 | #!/bin/bash |
---|
2 | # This script monitors the backend log |
---|
3 | # restarts backend if a firewire No Input in 300 msec... error occurs |
---|
4 | # Sends email if a recording fails |
---|
5 | |
---|
6 | set -e |
---|
7 | . /etc/opt/mythtv/mythtv.conf |
---|
8 | scriptname=`readlink -e "$0"` |
---|
9 | scriptpath=`dirname "$scriptname"` |
---|
10 | |
---|
11 | logfile=/var/log/mythtv/mythbackend.log |
---|
12 | # These errors are monitored: |
---|
13 | # 2011-10-19 02:00:01.067 Updating status for Flashpoint:Grounded on cardid 3 (Tuning => Recorder Failed) |
---|
14 | # 2011-10-09 11:00:00.857 Updating status for "Shake It Up!":"Shrink It Up" on cardid 7 (Recording => Recorder Failed) |
---|
15 | # 2011-11-10 10:19:00.575 Updating status for "Hawaii Five-0":"Thu Nov 10 09:04:00 2011" on cardid 7 (Recording => Recorder Failed) |
---|
16 | # 2011-10-09 19:12:34.361 LFireDev(00169204EBAE0000), Warning: No Input in 300 msec... |
---|
17 | |
---|
18 | tail -f $logfile | ( |
---|
19 | while true ; do |
---|
20 | read date time msg |
---|
21 | if [[ "$msg" == *' Recorder Failed)' ]] ; then |
---|
22 | msgtime=`date -d "$date $time" "+%s"` |
---|
23 | now=`date "+%s"` |
---|
24 | if (( now - msgtime < 60 )) ; then |
---|
25 | "$scriptpath/notify.sh" "Recorder Failed" "$msg" |
---|
26 | echo $date $time "$msg" |
---|
27 | fi |
---|
28 | fi |
---|
29 | if [[ "$msg" == *' No Input in 300 msec...' ]] ; then |
---|
30 | msgtime=`date -d "$date $time" "+%s"` |
---|
31 | now=`date "+%s"` |
---|
32 | if (( now - msgtime < 60 )) ; then |
---|
33 | if (( now - lastrestart > 300 )) ; then |
---|
34 | echo $date $time "$msg" |
---|
35 | echo "Restarting back end because of No Input in 300 msec" |
---|
36 | sudo restart mythtv-backend || echo "Restart failed" |
---|
37 | lastrestart=$now |
---|
38 | "$scriptpath/notify.sh" "Firewire Glitch" "$msg" |
---|
39 | fi |
---|
40 | fi |
---|
41 | fi |
---|
42 | done |
---|
43 | ) |
---|