Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Ingres Topics / April 2007

Tip: Looking for answers? Try searching our database.

Re: [Info-Ingres] Running Ingres SQL commands from a shell script        ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andre.laframboise@lac-bac.gc.ca - 26 Apr 2007 03:52 GMT
As far as checking the exit status, either check '$?' for the terminal
monitor return code.
Or redirect the sql output to a temp file which can then be grep'ed for what
you're
looking for.

sql DB_NAME <SQL_FILE >TEMP_FILE 2>&1 || Echo "Cannot connect to DB"
Cat or grep TEMP_FILE for desired string(s).  

Andre

-----Original Message-----
From: info-ingres-bounces@kettleriverconsulting.com
[mailto:info-ingres-bounces@kettleriverconsulting.com] On Behalf Of
Laframboise André
Sent: Wednesday, April 25, 2007 10:32 PM
To: dstromberg@datallegro.com; info-ingres@kettleriverconsulting.com
Subject: Re: [Info-Ingres] Running Ingres SQL commands from a shell script ?

Something simple would be to pipe the sql string to the sql util.
i.e. 'echo "sql commands;\\p\\g" | sql DB_NAME'

The double slash is not a typo, it's an escaped version of \p\g.

Andre

-----Original Message-----
From: info-ingres-bounces@kettleriverconsulting.com
[mailto:info-ingres-bounces@kettleriverconsulting.com] On Behalf Of Dan
Stromberg
Sent: Wednesday, April 25, 2007 9:33 PM
To: info-ingres@kettleriverconsulting.com
Subject: [Info-Ingres] Running Ingres SQL commands from a shell script?

Hi folks.

Is there any good way, from a shell script, to run SQL commands against
Ingres (perhaps via ingres' terminal monitor), and to get a useful exit
status from the SQL statements back to the calling shell?

I realize I could use something like python with an ODBC interface, but 1)
that seems kind of heavyweight for what I want to do and 2) I don't think
I'll be able to get permission to put an ODBC interface -on- the machines in
question.  It's pretty much whatever comes with CentOS 4.4 or not at all for
this project.

Ideal might be to have any exit stati and'd or or'd together (dare I say, at
the caller's discretion?), or to have an array of exit stati kind of like
bash's $PIPESTATUS array, except for a chronology of statements, not
concurrent-but-chained-together statements.

If I must, I could run the SQL statements (the ones with side effects, at
least) one a time though.

Any suggestions?

Thanks!

_______________________________________________
Info-Ingres mailing list
Info-Ingres@kettleriverconsulting.com
http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
_______________________________________________
Info-Ingres mailing list
Info-Ingres@kettleriverconsulting.com
http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
andre.laframboise@lac-bac.gc.ca - 26 Apr 2007 13:21 GMT
I've seen non-zero RCs when Ingres is down, database is inconsistent or
doesn't exist.

We run a simple script daily just to check if Ingres is up.
It checks the RC from an 'sql iidbdb </dev/null >/dev/null'

A non-zero is a problem and an email is sent out.

But, the return from an SQL statement is something else.
i.e. table doesn't exists.

Andre

 _____  

From: info-ingres-bounces@kettleriverconsulting.com on behalf of
"Wisniewski, Piotr, (ProService AT)"
Sent: Thu 4/26/2007 6:49 AM
To: Dan Stromberg; info-ingres@kettleriverconsulting.com
Subject: Re: [Info-Ingres] Running Ingres SQL commands from a shell script ?

BTW,
I'd like to know when does the SQL command return nonzero exit status.
Recently I upgraded to Ingres 2006 Version II 9.0.4 (a64.sol/105)
and I noticed that sometimes the exit status is set to nonzero when certain
SQL errors occur when running the sql script. I recall in previous versions
such errors did not cause nonzero exit status. The exit status was always 0
unless some invocation error occurred like when running
sql db < non_existing_file

-----Original Message-----
From: Dan Stromberg [mailto:dstromberg@datallegro.com
<mailto:dstromberg@datallegro.com> ]
Sent: Thursday, April 26, 2007 3:33 AM
To: info-ingres@kettleriverconsulting.com
Subject: [Info-Ingres] Running Ingres SQL commands from a shell script?

Hi folks.

Is there any good way, from a shell script, to run SQL commands against
Ingres (perhaps via ingres' terminal monitor), and to get a useful exit
status from the SQL statements back to the calling shell?

I realize I could use something like python with an ODBC interface, but 1)
that seems kind of heavyweight for what I want to do and 2) I don't think
I'll be able to get permission to put an ODBC interface -on- the
machines in question.  It's pretty much whatever comes with CentOS 4.4 or
not at all for this project.

Ideal might be to have any exit stati and'd or or'd together (dare I say,
at the caller's discretion?), or to have an array of exit stati kind of
like bash's $PIPESTATUS array, except for a chronology of statements, not
concurrent-but-chained-together statements.

If I must, I could run the SQL statements (the ones with side effects,
at least) one a time though.

Any suggestions?

Thanks!

_______________________________________________
Info-Ingres mailing list
Info-Ingres@kettleriverconsulting.com
http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres>  
_______________________________________________
Info-Ingres mailing list
Info-Ingres@kettleriverconsulting.com
http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres>
andre.laframboise@lac-bac.gc.ca - 27 Apr 2007 03:27 GMT
Man, I really gotta learn to proofread before clicking send.

Hope you can make out what I was trying to say.

Andre

 _____  

From: info-ingres-bounces@kettleriverconsulting.com on behalf of Laframboise
André
Sent: Thu 4/26/2007 5:46 PM
To: dstromberg@datallegro.com; Piotr.Wisniewski@psat.pl;
info-ingres@kettleriverconsulting.com
Subject: Re: [Info-Ingres] Running Ingres SQL commands from a shell script ?

If the you're using 'canned' SQl scripts and know what to expect, would it
be easier to look a
the output for a sign of success instead ?
Then anything else can raise somekind of flag because you don't know what
error may have occured.
 
Or will the script eventually have the smarts to take corrective action
depending on the error ?
 
The possibilities are can be endless.
 
Andre

 _____  

From: Dan Stromberg [mailto:dstromberg@datallegro.com
<mailto:dstromberg@datallegro.com> ]
Sent: Thu 4/26/2007 4:13 PM
To: Laframboise André; Piotr.Wisniewski@psat.pl;
info-ingres@kettleriverconsulting.com
Subject: RE: [Info-Ingres] Running Ingres SQL commands from a shell script?

Will the E_'s always be at the beginnnig of a line, at least?  I'm not sure
I want to say I can no longer fields that contain E_.

-----Original Message-----
From: andre.laframboise@lac-bac.gc.ca
[mailto:andre.laframboise@lac-bac.gc.ca
<mailto:andre.laframboise@lac-bac.gc.ca>  
<mailto:andre.laframboise@lac-bac.gc.ca
<mailto:andre.laframboise@lac-bac.gc.ca> > ]
Sent: Thu 4/26/2007 2:37 PM
To: Dan Stromberg; Piotr.Wisniewski@psat.pl;
info-ingres@kettleriverconsulting.com
Subject: RE: [Info-Ingres] Running Ingres SQL commands from a shell script?

Hi Dan,

The $? will be true because the Teminal monitor process itself was
successful (connected and ran the sql).

You want to scan the output for an error. You'll need to capture it and run
it through a filter (grep, awk, etc).

A grep for 'E_' should catch the errors unless you have db objets (tables,
columns) that start with E_.

Andre

 _____

From: info-ingres-bounces@kettleriverconsulting.com on behalf of Dan
Stromberg
Sent: Thu 4/26/2007 1:30 PM
To: Wisniewski, Piotr, (ProService AT);
info-ingres@kettleriverconsulting.com
Subject: Re: [Info-Ingres] Running Ingres SQL commands from a shell script?

Add to that:

I intentionally constructed an SQL query that should give an error, but
dividing by zero, by when I exited the terminal monitor, return code to bash

("$?") was true - not false as I would've hoped.

I did see an E_ error code at the beginning of a line though.  Can I grep
for "^E_" to see if there are errors?  And if so, how certainly is it that
this will match all errors and only errors?  EG, what if I had a table for a

ingres error codes - I don't want to mistakenly flag an error for any query
listing columns from it.

-----Original Message-----
From: "Wisniewski, Piotr, (ProService AT)" [mailto:Piotr.Wisniewski@psat.pl
<mailto:Piotr.Wisniewski@psat.pl>  
<mailto:Piotr.Wisniewski@psat.pl <mailto:Piotr.Wisniewski@psat.pl> >
<mailto:Piotr.Wisniewski@psat.pl  <mailto:Piotr.Wisniewski@psat.pl
<mailto:Piotr.Wisniewski@psat.pl> > > ]
Sent: Thu 4/26/2007 6:49 AM
To: Dan Stromberg; info-ingres@kettleriverconsulting.com
Subject: RE: [Info-Ingres] Running Ingres SQL commands from a shell script?

BTW,
I'd like to know when does the SQL command return nonzero exit status.
Recently I upgraded to Ingres 2006 Version II 9.0.4 (a64.sol/105)
and I noticed that sometimes the exit status is set to nonzero when certain
SQL errors occur when running the sql script. I recall in previous versions
such errors did not cause nonzero exit status. The exit status was always 0
unless some invocation error occurred like when running
sql db < non_existing_file

-----Original Message-----
From: Dan Stromberg [mailto:dstromberg@datallegro.com
<mailto:dstromberg@datallegro.com>  
<mailto:dstromberg@datallegro.com <mailto:dstromberg@datallegro.com> >
<mailto:dstromberg@datallegro.com  <mailto:dstromberg@datallegro.com
<mailto:dstromberg@datallegro.com> > > ]
Sent: Thursday, April 26, 2007 3:33 AM
To: info-ingres@kettleriverconsulting.com
Subject: [Info-Ingres] Running Ingres SQL commands from a shell script?

Hi folks.

Is there any good way, from a shell script, to run SQL commands against
Ingres (perhaps via ingres' terminal monitor), and to get a useful exit
status from the SQL statements back to the calling shell?

I realize I could use something like python with an ODBC interface, but 1)
that seems kind of heavyweight for what I want to do and 2) I don't think
I'll be able to get permission to put an ODBC interface -on- the
machines in question.  It's pretty much whatever comes with CentOS 4.4 or
not at all for this project.

Ideal might be to have any exit stati and'd or or'd together (dare I say,
at the caller's discretion?), or to have an array of exit stati kind of
like bash's $PIPESTATUS array, except for a chronology of statements, not
concurrent-but-chained-together statements.

If I must, I could run the SQL statements (the ones with side effects,
at least) one a time though.

Any suggestions?

Thanks!

_______________________________________________
Info-Ingres mailing list
Info-Ingres@kettleriverconsulting.com
http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres>  
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres> >
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres> > >

_______________________________________________
Info-Ingres mailing list
Info-Ingres@kettleriverconsulting.com
http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres
<http://www.kettleriverconsulting.com/mailman/listinfo/info-ingres>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.