Visit Our UNIX and Linux User Community

for loop with db2 command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting for loop with db2 command
# 1  
Old 10-05-2007
for loop with db2 command

Having some trouble with usage of for loop and displaying words. Basically I had 3 words( some times more )
in the variable. I want to get one at a time to process.

I am new to unix scripting so please bear with my question and appreciate your reply. I think this can also me done my awk command but I don't know how.. So appreciate your help.

Shell script is
db2 "connect to DB2D"

tempfile1=`db2 -x "select concat(pkgschema,concat('.',pkgname)) from
syscat.packagedep where bname='"$table_name"' and
bschema='"$schema_name"' with ur "`
echo ' ---tempfile after the db2 command ------- ' $tempfile1
for variable in $tempfile1; do
echo $tempfile1[0]

db2 "connect reset"

After the db2 command tempfile1 looks like ( 3 words seperated by blank)
sch1.package1 sch2.package2 sch3.package3

In the for loop also it shows like
sch1.package1 sch2.package2 sch3.package3 [0]
sch1.package1 sch2.package2 sch3.package3 [0]
sch1.package1 sch2.package2 sch3.package3 [0]

Expected output is
# 2  
Old 10-05-2007
I did it ..

Here is the code
count_args() # Returns count of input ARG_LIST
# Arg_n = ARG_LIST
echo $#

db2 "connect to DB2D"

tempfile1=`db2 -x "select concat(pkgschema,concat('.',pkgname)) from syscat.packagedep where bname='"$table_name"' and bschema='"$schema_name"' with ur "`
words=`count_args $tempfile1`
echo "$tempfile1 = $words words" > temp.out

tfile_length=`wc -l temp.out | cut -c1-8` tfile_len=`expr $tfile_length + 0`

while [ "$tfile_len" -ne 0 ]
tline=`tail -$tfile_len temp.out | head -1 | cut -c1-30`
echo $tline ";"
tfile_len=`expr $tfile_len - 1`

Previous Thread | Next Thread
Test Your Knowledge in Computers #685
Difficulty: Medium
Reverse Polish notation (RPN), also known as Polish programming notation.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
3 Replies

2. UNIX for Dummies Questions & Answers

Db2 command issues with cron

Hi, I have a very simple script that queries from a DB2 table. The script has 3 parts - (i) Sets the db2profile (ii) connects to db2 using credentials (iii) executes the query.This script works fine if i run it manually from the command prompt. However when scheduled in crontab, it proceeds... (2 Replies)
Discussion started by: VeePee
2 Replies

3. Shell Programming and Scripting

How to create DB2 Connections in While loop using shell script

Hi , I have to create a db2 connection for the while loop in shell scripting. Below is the connection for DB2 I have to establish connect to TABLESCHENMA user $USERID using $PASSWORD Below is the while loop. while read TABLE; do db2 LOAD CLIENT FROM $DIRECTORY/$TABLE.ixf OF ixf INSERT... (1 Reply)
Discussion started by: vikyalex4
1 Replies

4. Shell Programming and Scripting

DB2: load command in unix

I am currently trying to load data from e.txt into tablea. I am getting error. db2 connect to qw01p user wcs using abc db2 "LOAD CLIENT FROM /dswork/ECONT/output/interface/e.txt OF DEL MODIFIED BY coldel| SAVECOUNT 0 ROWCOUNT 0 WARNINGCOUNT 0 MESSAGES XTMPRTI1.txt REPLACE into WCSADM.TABLEA... (1 Reply)
Discussion started by: skatpally
1 Replies

5. Shell Programming and Scripting

how do i access db2 instance via telnet command prompt

Hi I have a perl script code in which connecting with db2 database and doing some process. My perl script code and db2 database server present in the same unix server. I am connecting and executing perl script code via windows telnet. Now my question is i could not able to connect db2 server... (4 Replies)
Discussion started by: solo123
4 Replies

6. Shell Programming and Scripting

Run DB2 export command in loop

Hi All, I have list of 100 table names in a file, how to read table name from and pass to DB2 export command and run for all tables in loop. Please help me with script. db2 EXPORT TO ~/data_export/<table name from file>.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.<Table Name... (4 Replies)
Discussion started by: srimitta
4 Replies

7. Shell Programming and Scripting

Executing DB2 command without using the DBI module

Hi Guys, I wonder if possible to execute a Db2 commands within a perl scripts without installing or invoking the DBI modules. I have a script that is written in kron shell and it looks like : DB=`db2 list db directory | egrep "Database alias|Directory entry type"|awk '{printf $0 ;... (0 Replies)
Discussion started by: arizah
0 Replies

8. UNIX for Dummies Questions & Answers

Unable to get the db2 command prompt in unix

Hi, When i try to connect to the db2 database from unix solaris 5.8 version by typing "db2" from the .../sqllib/bin/ folder, i am not getting the db2 command prompt. Could anyone help me resolve this? Here the db2 is executable only. But still iam not getting the db2 prompt. The error i get is... (4 Replies)
Discussion started by: ragavhere
4 Replies

9. UNIX for Dummies Questions & Answers

Exception while loading DB2 driver Class.forName("")

Hi... I m working on UNIX z/OS. Actually i have to pass the parameters from the JCL to java-db2 program thru PARM. I am able to pass the arguments but the problem occured is, it is throwing an exception while loading the db2 driver as ''... (0 Replies)
Discussion started by: Sujatha Gowda
0 Replies

10. AIX

db2 command on the AIX mechine

Hello, can any one help me to debug the following command. db2 -stec +pc ; Regards, SM (2 Replies)
Discussion started by: smolgara
2 Replies

Featured Tech Videos