Command Line execution of sql statement
Posted in 2003
Topics: Server Administration
Hi all,
I am not sure how to do this, but what I want to do is have a cron
job execute a sql statement and dump the results in to a comma
delimited file. I know how to do everything but actually execute the
query. I have led to believe that this can be done with isql or
dbaccess. Any help would be appreciated.
John M wrote:
>Hi all,
> I am not sure how to do this, but what I want to do is have a cron
>job execute a sql statement and dump the results in to a comma
>delimited file. I know how to do everything but actually execute the
>query. I have led to believe that this can be done with isql or
>dbaccess. Any help would be appreciated.
>
>
dbaccess databasename scriptname
You will have to re-direct stdout and stderr to avoid e-mails from cron.
HTH
Michael
John M wrote:
> I am not sure how to do this, but what I want to do is have a cron
> job execute a sql statement and dump the results in to a comma
> delimited file. I know how to do everything but actually execute the
> query. I have led to believe that this can be done with isql or
> dbaccess. Any help would be appreciated.
Everybody told you how to write the SQL into a file and then run it
with either DB-Access or ISQL. No-one mentioned that you have to
ensure that the environment is set correctly because cron does not do
it for you.
Oh, and SQLCMD from the IIUG archives allows you to write:
sqlcmd -d dbase -D, -e 'select * from wherever'
The -D, bit sets the delimiter to comma instead of pipe; if you want
quoted data for strings, then you don't do that but use -F csv or -F
quote (depending on how much of the data you want quoted). Find
SQLCMD in the IIUG Software Archive.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/