Sybase connection failing through shell script

Hi All,

I'm trying to connect to Sybase via shell script. i'm getting the following error.
Please let me know where i'm going wrong. Note that i'm not having this issue when connecting via terminal.

#!/usr/bin/bash

SYBASE=/usr/sybase
ISQL=$SYBASE/bin/isql

export SYBASE ISQL 

$ISQL -Uuser -Ppwd -Sfoo <<EOF
use db
go
select count(*) from some_table
go
EOF

error:
ct_init(): network packet layer: internal net library error: Attempt to load protocol driver failed
Attempting to obtain a localized error message failed.

Add your Sybase library directories to LD_LIBRARY_PATH environment variable.

export LD_LIBRARY_PATH="/usr/sybase/lib/:$LD_LIBRARY_PATH"

Replace highlighted section with relevant directories. I hope this helps.

---------- Post updated at 11:26 ---------- Previous update was at 11:21 ----------

For further reference: Sybase Environment Variables

This page also suggest to source SYBASE.csh or SYBASE.sh in your script to set environment variables.

HI mate,

i tried the above solution, still get the same error.

#!/usr/bin/bash
LD_LIBRARY_PATH="/usr/sybase/ASE-12_5/lib:$LD_LIBRARY_PATH"
SYBASE="/usr/sybase:$SYBASE"

/path/to/dir/isql -Uuser -Ppwd -SFOO <<EOF
use db
go
select count(something) from some_table
go
EOF

error :


Msg 4002, Level 14, State 1:
Server 'FOO':
Login failed.
CT-LIBRARY error:
        ct_connect(): protocol specific layer: external error: The attempt to connect to the server failed.

Now that is a different error message.

As per Sybase, this message is a generic login failure message that does not tell the connecting user whether the failure resulted from a bad user name or a bad password. This generic message guards against malicious attempts to gain access to Adaptive Server.

Reference: Login failure to Adaptive Server

hey ,

thanks for the quick reply. I connected to the Database with the same credentials from the terminal and it works. for some reason it fails when i call it from within the shell script.

cheers

I'm sure it's not magic! If it works in one place and not the other, this strongly suggests that you environment is not the same in both places. Compare the environment from your "terminal" to the one your script sees, using env.

edit: and don't forget to export the appropriate environment variables.

Yes, I totally agree with Scott. I do not see any syntax error in your code. It should work!

BTW I see you have added $SYBASE_ASE to LD_LIBRARY_PATH

Can you also add $SYBASE_OCS & $SYBASE_FTS suggested by the manual. Also compare the env as suggested by Scott.