Post by D_PeglowPost by r***@yahoo.co.inI am new to this group and looking for a good tutorial to start with
sybase. I would like to know about how to execute the queries within a
script. Please help.
There a several ways to do it.
#!/bin/sh
isql -U<USER> -P<PASSWORD> <<SQL
SELECT *
FROM Table
GO
SQL
# End
Or put yor query in a file query.sql
#!/bin/sh
isql -U<USER> -P<PASSWORD> -i query.sql
# end
Dietmar
Some enhancements to Dietmar's ideas:
To avoid confision... the "SQL" in the above isn't saying put your SQL
here... it's a delimiter that tells the script the beginning and the
end of the actual statement. You can put any delimiter here... I
usually use an exclamation point.
Some issues if security is a concern:
Ideally, you'll create a password variable, and populate it with some
other command that grabs it, encrypted, from some location before
calling the ISQL. Then, instead of specifying the -P on the isql
command line, put the password variable as the very first line of your
SQL. Otherwise the password will appear plain text to anyone who does
a 'ps' on the box while the isql is running.
So you would have:
#!/bin/sh
## Call some script to retrieve the password
SYBASE_PW=`/somepath/.get_password`
## Execute the sql
isql -Uuser -Sserver << ! >>
$SYBASE_PW
select * from table
go
!
At the very least, if you don't have a password generation script and
have to hard code the password into the script, put it within the isql
as above so it doesn't show up when doing a 'ps', and set read access
on the script to only those who should know the password.
You could pass the password in on the command line, but again, doing
this causes it to appear when doing a PS during the entire time the
script is running (as opposed to only when the isql statements are
running). If this is an interactive script you could prompt for the
password of course.
Just keep in mind that the password has to be on a line by itself as
the first line if your sql statement inside of your delimiter ('!',
'SQL', or whatever else you choose).
The method of passing in the sql with the -i option also works, but
again with this option you allow the password to be clearly displayed
on a 'ps' listing while the isql is running.
-Mike