#!/bin/bash

export QTDIR=/usr/lib/qt3
/usr/local/bin/mythfilldatabase

# The minimum number of days you will allow before you
# want to receive a notification message
MIN_DAYS=3

# The e-mail address to send the warning message to
EMAIL=root

DB=mythconverg
SQL='SELECT TO_DAYS(max(endtime)) - TO_DAYS(now()) FROM program;'

DAYS_LEFT=`mysql --skip-column-names -B -D $DB --execute "$SQL"`

if [ $DAYS_LEFT -lt $MIN_DAYS ]; then
       mail -s "[MYTHTV] Only $DAYS_LEFT days of programs left!" $EMAIL <<-END
               Maybe you should check if mythfilldatabase is configured
               correctly or that your XMLTV service provider is still
               on-line?
       END
fi
