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

Tom Dexter digitalaudiorock at gmail.com
Mon Feb 16 01:53:29 UTC 2009


On Sun, Feb 15, 2009 at 6:51 PM, Drew Tomlinson <drew at mykitchentable.net> wrote:
> 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.
>
> Thanks,
>
> Drew
>
> --
> Be a Great Magician!
> Visit The Alchemist's Warehouse
>
> http://www.alchemistswarehouse.com
>
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
>

Whenever I have to do anything of that sort I use something with a
real mysql database interface, such as php (as David suggested) or
perl using the perl DBI and the DBD::mysql driver (if you're familiar
with either).  Either of those have all sorts of ways to retrieve data
into actual arrays, or arrays of arrays etc.  What's even more
convenient is that they both support SQL placeholders...that is, where
the SQL can be anything like "SELECT some_column WHERE whavever=?" and
you can use arrays to feed the ? placholders eliminating the need to
escape special characters etc.  In bash you'd be pretty much stuck
trapping the text output and parsing it.

Tom


More information about the mythtv-users mailing list