LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-19-2011, 12:36 PM   #1
zunder1990
LQ Newbie
 
Registered: Feb 2011
Posts: 29

Rep: Reputation: 3
Bash scripting and mythtv


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
Code:
#!/bin/bash
#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 "#"

do

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

where=`locate "$filename.mpg"`
#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.

fi

done < "$file"
This is mysqlcmd
Code:
#The bottom part is one line
USE mythconverg;

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
Code:
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.
 
Old 05-19-2011, 09:16 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
Well I dont care the code works.
So does this mean you want feedback? Seems an odd post as you don't really have a question??
 
Old 05-19-2011, 09:43 PM   #3
zunder1990
LQ Newbie
 
Registered: Feb 2011
Posts: 29

Original Poster
Rep: Reputation: 3
I posted this for any that would like to use. I said that because last time that I posted code someone told that all of my code was wrong and start to tell what I was doing wrong.
 
  


Reply

Tags
bash scripting, mythtv



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting Help TechVandal Programming 5 03-01-2009 03:22 PM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
Bash Scripting B-Boy Programming 2 05-28-2008 01:15 AM
Bash scripting help arturhawkwing Linux - General 1 08-10-2006 11:54 AM
Bash scripting SWAT Linux - Newbie 2 11-11-2003 03:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration