Run script to export the data to ixf file in loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run script to export the data to ixf file in loop
# 1  
Old 04-04-2012
Run script to export the data to ixf file in loop

Hi,
I am trying to export the data to an .ixf file.
I have read the table names from a .dat file and those table name should be passed to the select * from schema.TABLENAME query .

I am trying the below loop
Code:
while read TABLE; do

  db2 EXPORT TO ~/data_export/$TABLE.ixf OF IXF MESSAGES messages.txt SELECT * FROM schema.$TABLE 
done <file_which _has_tableNAmes

I am getting the following error..

Code:
SQL0104N  An unexpected token ""TABLENAME"" was found following 
"<identifier>".  Expected tokens may include:  "OF".  SQLSTATE=42601

Please help

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them
# 2  
Old 04-04-2012
Though I'm not familiar with this db2 command it looks unlikely.
Does the db2 command work when typed at the command line?
I have no idea where "TABLENAME" came from unless it is in your input file. I do hope that your input file has not got headings!

From a shell scripting point of view, the asterisk needs protecting from Shell filename globbing.

Code:
while read TABLE; do

  db2 EXPORT TO ~/data_export/$TABLE.ixf OF IXF MESSAGES messages.txt SELECT \* FROM schema.$TABLE 
done <file_which _has_tablenames

# 3  
Old 04-04-2012
Hi Methyl,

The TABLENAMES are in the input file ..
the input file looks like this
Code:
"tablename1"
"tablename2"
"tablename3"

etc...


Last edited by Scrutinizer; 04-04-2012 at 05:04 PM.. Reason: code tags
# 4  
Old 04-08-2012
It think one of the problems the problem is the quotes round the table names in you input file, but still have no idea where the string "TABLENAME" came from in the error message you posted.

Ignoring Shell script, do you have a sample command which works from the unix command line?
# 5  
Old 04-09-2012
Hi Methyl,

I am using the below script to load the data into tables and it is working fine...but its creating db connection eveytime because its in the while loop..
and idea how can i create the connection globally and read the sql in the while loop..
Code:
while read TABLE; do
  echo "$TABLE"
cat> $loadsql << EOF

connect to $DB_CAT_PPSTAGE user $PSTGUSERID using $PSTGPASSWORD 
@
 LOAD CLIENT FROM $data_dir/$TABLE.ixf OF ixf REPLACE INTO $TABLE NONRECOVERABLE INDEXING MODE REBUILD ALLOW NO ACCESS
@
EOF
sh " db2 -td@ -f $loadsql"

 done < $input_file
 exit


Last edited by Franklin52; 04-09-2012 at 12:37 PM.. Reason: Please use code tags for data and code samples, thank you
# 6  
Old 04-09-2012
Untested (and I don't know the rules for db2 command sequences), but my first idea is to try generating the complete load script concatonated before executing the database load. For example:

Code:
> ${loadsql}   # Create empty db2 script file

# Append: Connect to database
cat >>${loadsql} << EOF
connect to $DB_CAT_PPSTAGE user $PSTGUSERID using $PSTGPASSWORD 
@
EOF

# Append: Create as many database load lines as needed
while read TABLE; do
echo "$TABLE"
cat >>${loadsql} << EOF
LOAD CLIENT FROM $data_dir/$TABLE.ixf OF ixf REPLACE INTO $TABLE NONRECOVERABLE INDEXING MODE REBUILD ALLOW NO ACCESS
@
EOF
done < $input_file

# Execute the connect and all the load lines
sh " db2 -td@ -f ${loadsql}"

exit



Footnotes:
1) None of your posted samples issue a command to disconnect from the database conection. Is this a feature of db2?
2) The example does not set a value for $data_dir or $input_dir and a lot more variables.

Last edited by methyl; 04-09-2012 at 03:49 PM.. Reason: multiple edits
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Script to Gather data from logs and export to a CSV file

Greetings, After a few hours of trial and error, I decide to ask for some help. I am new to AWK and shell script, so please don't laugh :p I made the below script, to gather data from some logs and have the output into a CSV file : #!/bin/sh #Script to collect Errors ... (9 Replies)
Discussion started by: Yagami_Sama
9 Replies

3. Shell Programming and Scripting

Data export UNIX shell script

Hi, I want to write a shell script which connect to my database with the following credentials : User name : user PWD : rap_user_1 Hostname : app.Unix.Gsm1900.Org Port : 7862 SID : PTNC1 Once connected to DB i want to fetch data with the help of a SQL statement and expoet... (4 Replies)
Discussion started by: neeraj617
4 Replies

4. AIX

wtmp file - is there a patch to export the data another file each day?

sorry for being a noob, i am trying to find which user accessed the server at what time and there ip address at first i used who command but the output didn't contain the ip address then i used the last command which provided me with the ip of the users but when i searched i searched and found that... (1 Reply)
Discussion started by: hercules_1010
1 Replies

5. Shell Programming and Scripting

Shell script to export data from Oracle table .

Hi, I want to write a shell script which will export data from oracle table . I don't want to save that data . I want the queries . Right now i am right clicking on the table and clicking on export as to my desktop . Please let me know if any one have any idea . (2 Replies)
Discussion started by: honey26
2 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

How to export table data to xml file?

Hi , I would like to get some suggestion from the experts. My requirement is to export oracle table data as an xml file. Any unix/linux tools, scripts available? Regards, (2 Replies)
Discussion started by: LinuxLearner
2 Replies

8. Shell Programming and Scripting

help for writing shell script to export table data

Hi All, I need to write a shell script(ksh) to take the tables backup in oracle(exporting tables data). The tables list is not static, and those are selecting through dynamic sql query. Can any body help how to write this shell script. Thanks, (3 Replies)
Discussion started by: sankarg
3 Replies

9. Shell Programming and Scripting

unix script to export data from csv file to oracle database

Hello people, Need favour. The problem I have is that, I need to develop a unix shell script that performs recurring exports of data from a csv file to an oracle database. Basically, the csv file contains just the first name and last name will be dumped to an Unix server. The data from these... (3 Replies)
Discussion started by: vinayagan
3 Replies

10. UNIX for Dummies Questions & Answers

How to export data file from Unix

Hi, I am searching a way to export data file on Unix to SQL server on a daily bases. Any one has any ideas? Thanks in advance! (20 Replies)
Discussion started by: whatisthis
20 Replies
Login or Register to Ask a Question