[mythtv-users] Ways to Query Database From sh Script?

C.T. Paterson i.adore.my.64 at gmail.com
Mon Feb 16 01:34:03 UTC 2009


2009/2/15 Drew Tomlinson <drew at mykitchentable.net>:
> I'm working on my first UserJob script.  In this script, I want to test
> if a recording has a cutlist before processing.  I've Googled and the
> way found to query the database from /bin/sh goes like this:
>
> CUTLIST=`cat << EOF | mysql -u mythtv -pmythtv mythconverg
>        SELECT
>                cutlist
>        FROM
>                recorded
>        WHERE
>                basename = '$FILENAME';
> EOF`
>
> Using the above, $CUTLIST will be set to either "cutlist 1" or "cutlist
> 0" depending upon whether a cutlist exists. (I suppose piping to awk
> would remove "cutlist").  Is this the only way to query from /bin/sh?
> Is there a more practical way?
>
> I'm pretty new to this stuff so if the answer is obvious, nudges to the
> relevant links would be appreciated.

What I like to do for queries I'll be executing many times is to write
my SQL into a file, ie.

# cat "select * from recorded;" > ~/mysqlfile.sql

...and then call the file from the command-line via:

# mysql <databasename> -u<username> -p<password> < ~/mysqlfile.sql

The results are dumped to standard out, and you can assign, parse,
redirect as you see fit.

Cheers.

-- 
"My country is the world, and my religion is to do good."
                                        -- Thomas Paine


More information about the mythtv-users mailing list