Re: dbaccess fail status to Bourne shell exit status
Posted in 1999
Steve
AFAIK, the OOPS is because dbaccess finds the TERM setting incorrect and
cannot render on the physical terminal given the settings of the existing
TERM. Not to nitpick at your solution, but you could also try:
dbaccess database_name /your/sql/script/somewhere/something.sql
2>/tmp/sql.log
if [ `grep -ci "error" /tmp/sql.log` -gt 0 ]; then
echo "An error has occured."
cat /tmp/sql.log
else
echo "Successfull"
fi
This will give you output that you will be able to control (in terms of
OOPS occurences :-)).
HTH
Sujit
steve_roach@NOSPAMibm.net (Stephen Roach) on 04/23/99 04:54:22 PM
Please respond to steve_roach@NOSPAMibm.net
To: informix-list@iiug.org
cc: (bcc: Sujit Pal)
Subject: Re: dbaccess fail status to Bourne shell exit status
On Tue, 20 Apr 1999 21:19:56 GMT, roach@NOSPAMportalinc.com (Stephen
Roach) wrote:
> Hi folks
>
> I want to invoke dbaccess through a Unix script and drop a table. If
> the table does not exist, I want the Unix script to report this using
> $?. dbaccess just executes a sql file with a single drop statement.
> Any ideas?
>
> TIA
>
> Steve
Thanks for the replies, good people. They helped a lot. This is the
solution I eventually implemented, warts and all:
My table drop script exists in another part of the file system than
the unix script used to invoke it. The unix script is only supposed to
help with maintenance of the database and I don't want to mess with
the other elements.
The script now reads:
dbaccess <database name> -qcr <drop script path>/$1 > status.out 2>
/dev/null
if grep "TableOOPSdropped." ./status.out > /dev/null
then
echo "Table dropped."
...
else
echo "Drop failed."
...
fi
If I don't redirect standard error to null, status.out containes a lot
of control characters and the grep fails. dbaccess seems to be
apologising for itself rather a lot because in the non-control char
version of status.out, the characters OOPS appears all over the place,
including between the words of and messages.
Someone suggested [ -n `grep "Table dropped" status.out` ] as the test
but I can't seem to get this to work (even with adding the OOPS!).
Like I said, this solution has warts and I don't fully understand why
some of the effects described above occur. However, this does the job
and that's all I need right now. It also has the advantage of being
able to test for any message condition assuming the right form and
OOPS' are included in the test. I guess the alternative would be to
test for the error number but I am a bit worried that the output may
throw up a number out of context.
Thanks for all your help.
---------------------------------------------------------
Steve Roach: Remove NOSPAM from address to reply:
steve_roach@NOSPAMibm.net
steve_roach@NOSPAMhotmail.com