Re: Capture return from sybase in shell script



The nice (confusing?) thing about UNIX shell scripting is that there are usually a half dozen (or more) ways to do something ... often times coming down to the developer/programmer's preference.

The general format for grep is:

grep "some_string_to_search_for" <filename>

The above command will echo all lines (from <filename>) that contain 'some_string_to_search_for".

A simple test in ksh could look something like:

------------------------------
# if 'ERROR' shows up in our output file then
# do some additional processing

if [[ `grep "ERROR" /tmp/isqlTester.dat` != '' ]]
then
	... do some schtuff here ...
fi
------------------------------

Even just using grep the above can be written several different ways within just the ksh itself ... the backquote is a somewhat out-dated construct ... the double brackets can be replaced with single brackets if you use a different test operator ... etc, etc, etc. ... but this should give you a general idea.

There's nothing wrong with using perl other than the fact that it's typically a little harder to learn than (sh,ksh,csh,bash) shell scripting.

Then again, shell scripting can get 'complicated' depending on how deeply you want to delve into said shell script's abilities.

dufffman@xxxxxxxxx wrote:

Thanks for your input Mark.  I am new to the unix env. and it seems
that I've been hearing this a lot lately.. "now if you were to use
perl...."  seems like the time for transition is not too far away!

Could you possible give me an example of how to use grep like you
mention it below?  LIike I said I am new, and I could think of how to
use sed to extract the value from a file, but would be interested in
knowing how grep could use it also.

Lets asume the stroed proc prints out the final value.  And all output
from this ISQL session is directed to /tmp/isqlTester.dat

How would you use the command?

Thanks,

Mark A. Parsons wrote:

Since you can execute lots of queries and stored procs within a single isql
session it is not possible to have one stored proc's return status kicked
out as the status ($?) for the isql command.

Assuming a plain-vanilla k/sh shell script a couple options come to mind:

1 - instead of having stored proc return a '-1', have it 'print' (select?)
a statement; then grep for this statement in your isql output

2 - after the 'exec @ret_stat = <proc_name>' line, have some code in your
isql session which tests the value of @ret_stat and then 'print' (select?)
an appropriate statement; then grep for this statement in your isql output

Obviously (?) if you were to use something other than ISQL (eg, perl) you
could be a little more creative/selective in how you handle individual exec's.

dufffman@xxxxxxxxx wrote:


Hi,

I am writing a script that calls a stored proc using ISQL.  In certain
cases I want to return -1 if the desired output is not there.  I tried
using a 'return' statement in my stored proc, but when I tried to
capture the return status in shell using '$?' it still gives a 0.

Can anyone recommend a good way of throwing erros in a stored proc that
a shell would be able to capture?

Thanks,



.



Relevant Pages

  • Re: Capture return from sybase in shell script
    ... Could you possible give me an example of how to use grep like you ... > Since you can execute lots of queries and stored procs within a single isql ... then grep for this statement in your isql output ... >> I am writing a script that calls a stored proc using ISQL. ...
    (comp.databases.sybase)
  • Re: Shell-Script Question
    ... >whether the variable is greater zero, but I have no clue how I get the ... Actually you can do this in one step since grep will return an exit ... If you want to learn more about shell scripting then you can't go ...
    (linux.redhat)
  • Re: package rename (refactoring ) from command line
    ... Wish some shell scripting using sed and ... grep you should be able to do a blind find/replace to your files. ... can invoke that script as a part of ant before the compile target. ...
    (comp.lang.java.programmer)