I tested this on mythtv 0.23 and Ubuntu 10.10. The script file is called mysql.sh and it is located at /home/user/mysql.sh . The other file is called mysqlcmd and is at /home/user/mysqlcmd.
This is mysql.sh
#Wrote by Zach Underwood on 5-19-2011
#This script will look in the mythtv database for show that are newly record.
#Then copy them to another place.
#On the way of being copied it will rename it to something human readable.
day=`date -d 'yesterday' +%Y-%m-%d` #This will get yesterday day in the format of 2011-04-21.
sudo rm -f /tmp/recordedprogram #This will remove a temp file
sudo rm -f /tmp/recordedprogramnospace #This will remove a temp file.
mysql -h localhost -u root -ppassword < /home/zach/mysqlcmd
#This will read that mythtv database to see what has be recorded that output it to /tmp/recordedprogram
cat /tmp/recordedprogram | sed 's/ /-/g' >> /tmp/recordedprogramnospace
#This will read the file and replace all spaces with -
file=/tmp/recordedprogramnospace #This will set the temp file with no spaces
while IFS=# read -r chanid starttime title subtitle
#this will read one line at a time a read the different fields into memory and it sets the delimiter to "#"
filename=`echo "$chanid"_$starttime | sed 's/://g' | sed 's/ //g' | sed 's/-//g'`
#this will read and get the file name in the form of 2211_20110518200000 and this is what mythtv store video named
#this will read the filename from above and add .mpg to the file name and then will look for the file.
#With mythtv video can be in more than one different folders on the filesystem
fileplace=`echo "$where" | grep -v .png`
#This will read the location of the files from above and remove and that end in .png.
something=`echo $starttime | cut -c 1-10`
# This will read the start time put in the format of 2011-04-21
if [ $day = $something ]; then
#them compares the start time of the video file and yesterday's date and if they match then it will copy to anywhere you want.
sudo cp $fileplace /data/smb/"$title"_"$subtitle".mpg #This is what copies the video and rename it too.
done < "$file"
This is mysqlcmd
#The bottom part is one line
SELECT chanid, starttime, title, subtitle from recordedprogram into outfile '/tmp/recordedprogram' FIELDS TERMINATED BY '#';
To run then command you will need to pass your password into
echo "password" | sudo -S /home/user/mysql.sh
By the way I know that the code is not the most clean or that it is not the best way to write code. Well I dont care the code works. I did not write this for a company, I wrote this for home. I also know that mythtv has some scripts that could do this but I could not get them to work or they could not do what I want.