linux:vdr_konflikt_mail
Table of Contents
Send Mail when VDR timer-conflict occurs script-based
Context
Problems:
- I'm using my vdr without a client and without OSD.
- I doesn't find a pleasant possibility to send a mail when a conflict occurs.
- By using epgsearch, a conflict could arise without noticing.
- A existing Perl script wasn't possible to use for me because I have installed postfix and mailx not sendmail.
Prerequisite
- All logs produced by vdr are collected by syslog-ng into a single file so that can be analysed.
Syslog-ng.conf (part of it):
Monitoring the log
- Every 30min, or something like that, vdr checks for timer-conflicts (It's a German System)
Apr 2 17:20:00 vdr: [6734] EPGSearch: timer conflict check started Apr 2 17:20:00 vdr: [6718] info: 1 Timer-Konflikt(e)! Erster am 02.04 20:38. Anzeigen? Apr 2 17:20:08 vdr: [6734] EPGSearch: timer conflict check finished
Analysing the log isn't complicated:
- mailx only works without additional options when postfix is configured properly
- vdr_timer_konflikte.sh
#!/bin/bash ######################### ##vdr Timer-conflicts and send mail ##30.03.2010 ######################### LOGDATE=`date '+%Y-%m'` DAY=`date '+%d'` LOGFILE="/syslog/vdr/$LOGDATE/vdr.log.$DAY" LOCKFILE="/tmp/timer_konflikt_$DAY.lock" ACTFILE="/tmp/timer_konflikt.log" DATE=`date '+%A %d. %b %Y %H:%M:%S'` MAILTO="user@example.com" SUBJECT="ALERT vdr Timer-conflict($DATE)" ############################################################### /usr/bin/find /tmp/ -name *timer_konflikt* -mtime +1 -exec rm -f {} \; GREP=`/bin/grep "Timer-Konflikt" $LOGFILE` # wenn grep was gefunden rückgabe = 0 if [ $? == 0 ];then GREP=`/bin/grep "Timer-Konflikt" $LOGFILE | tail -1 | cut -d : -f 5-6` #GREP=`/bin/grep "Timer-Konflikt" $LOGFILE | tail -1 | cut -c 40-120` # check mail already send touch $ACTFILE touch $LOCKFILE echo $GREP > $ACTFILE /usr/bin/diff $ACTFILE $LOCKFILE > /dev/null if [ $? != 0 ];then echo $GREP > $LOCKFILE TEXT="A Conflict in a Timer occured in the logfile.\nPleas check.\n\n" TEXT="$TEXT$GREP" TEXT="$TEXT\n\nhttp://vdr.example.org" TEXT="$TEXT\nhttp://vdr.example.lan\n" TEXT="$TEXT \n\n\n\nYour faithful employee,\n\nyour vdr!" echo -e $TEXT | /usr/bin/mailx -s "$SUBJECT" $MAILTO fi rm -f $ACTFILE
linux/vdr_konflikt_mail.txt · Last modified: 23.03.2013 17:44 by eanderalx