Bourne shell script with embedded Sybase SQL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bourne shell script with embedded Sybase SQL
# 1  
Old 10-22-2008
Tools Bourne shell script with embedded Sybase SQL

Hi,

I need a simple (as possible) Bourne shell script that takes an input file of adminID's and spits out a list of adminID's and related tradeID's.

Both adminID and tradeID are columns in a Sybase database table called "trades", in which they have a one-to-one relationship.

adminID is a string column and tradeID is an integer column.

The input file may have up to thousands of adminID's.

Preferably, the order of the adminID's would be preserved.

Thanks in advance for any input whatsoever.

Regards, Elizabeth Smilie
# 2  
Old 10-23-2008
Can you post an example of such an input file?
# 3  
Old 10-23-2008
Yes, here are 2 sample input files:

adminIDs.txt (19 lines)
adminIDs2.txt (4444 lines)
# 4  
Old 10-23-2008
I don't know how to connect to a Sybase db and it's been ages since I wrote any SQL at all, but I think the main idea would be to:

1. Build an SQL file from that admin.txt list (via shell script)
2. Connect to Sybase DB and execute SQL
3. Capture or export output from that SQL statement

I can't help you with the two latter points, but to construct the SQL file you could do something like this:

Code:
for i in `cat adminIDs.txt`; do echo SELECT adminID, tradeID from trades WHERE adminID = \'$i\'\;; done

You would get an output a bit like this:

Code:
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZL8XX517';
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZUXX667';
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZUXX668';
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZUXX669';
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZUXX67X';
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZUXX68X';
SELECT adminID, tradeID from trades WHERE adminID = 'X8ZUXX681';
etc.

I'm sure that can be optimized to use less SELECT statements, but I guess you get the idea.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 ... (6 Replies)
Discussion started by: Irishboy24
6 Replies

2. Solaris

Sybase Connectivity Check through Shell Script

Hi, I need to check the sysbase database connectivity through the Unix Shell Script. Can you help me on the how to write the script to test the sysbase database connection. Thanks in Advance Nandha (0 Replies)
Discussion started by: nandha2387
0 Replies

3. Shell Programming and Scripting

Assigning return value of an embedded SQL in a shell script variable

I've a script of the following form calling a simple sql that counts the no of rows as based on some conditions. I want the count returned by the sql to get assigned to the variable sql_ret_val1. However I'm finding that this var is always getting assigned a value of 0. I have verified by executing... (1 Reply)
Discussion started by: MxC
1 Replies

4. Shell Programming and Scripting

help with bourne shell script

Attempting to write a script to eventually notify me via email for when there is packetloss across the backbone. I am looking for values greater than 0% in the mtr field. #!/bin/sh target=www.google.com date +"%D"_"%T" >> /home/rich/mtr.log echo "----------------------------------------" >>... (1 Reply)
Discussion started by: closedown
1 Replies

5. Shell Programming and Scripting

Capturing Sybase SP output in Shell Script

Greetings, I need to capture the output of a Sybase stored procedure, inside my shell script( k shell). Based on this output, I need to call another perl script, with input arguments as the result set of the procedure execution. I need to keep looping through and call the perl script, ... (2 Replies)
Discussion started by: rajpreetsidhu
2 Replies

6. UNIX for Dummies Questions & Answers

sybase connection through shell-script

:mad: how do i connect to sybase through shell script written in linux (9 Replies)
Discussion started by: Amitabh
9 Replies

7. UNIX for Dummies Questions & Answers

How to authenticate sybase login thru shell script ?

Hi All, This is my first post. Need your favour guys. I need to authenticate syabse login/password thru shell script. I am getting the ID & Pwd form user and storing it in variable.. But how to authenticate and echo user back if the id/pwd doesnt work. isql -U$1 -P$2 -S$3 ?? thanks in... (3 Replies)
Discussion started by: libin4u2000
3 Replies

8. Shell Programming and Scripting

Connecting to sybase via shell script.

Hi All, I was able to connect to sybase in shell script and also able to run few sql queries, something like this, #!/usr/bin/ksh -x temp=`echo "select name from sysobjects where type = 'U'"` results=`isql -SDS_SERVER-UAdhocUser -Pha12 <<EOF set rowcount 6 $temp go EOF` line_count=0... (1 Reply)
Discussion started by: arvindcgi
1 Replies

9. Shell Programming and Scripting

cd from a Bourne Shell Script - Please Help

Dear Bourne Shell Expert, I am trying to change the current working directory from within a Bourne Shell script. Simply enough i thought ! As I am sure you are well aware, Inside the script i echo `pwd` and it seems ok, but the shell spawns another shell to execute this and as such, when my... (10 Replies)
Discussion started by: fawqati
10 Replies

10. Shell Programming and Scripting

Embedded SQL in AWK script

Hi All, Can I use AWK script to read data from Oracle table (some embedded SQL perhaps) The reason for this that I have a data file and I need to do some basic validations of the data in the file with some statistical figures related to the data file that I have stored in a Oracle table. Thanks... (2 Replies)
Discussion started by: 2nilotpal
2 Replies
Login or Register to Ask a Question