Run DB2 export command in loop | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Run DB2 export command in loop

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-04-2010
srimitta srimitta is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 13 May 2014, 8:25 AM EDT
Location: Indianapolis
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
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.


Code:
db2 EXPORT TO ~/data_export/<table name from file>.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.<Table Name from file>"

Thanks
Srimitta

Last edited by Scott; 08-04-2010 at 06:55 PM.. Reason: Added code tags
Sponsored Links
    #2  
Old 08-04-2010
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 20 October 2014, 2:03 AM EDT
Location: Zürich
Posts: 8,484
Thanks: 332
Thanked 1,047 Times in 914 Posts

Code:
$ cat file_with_table_names
table1
table2
table3

$ xargs -I{} echo db2 EXPORT TO \~/data_export/{}.ixf OF IXF MESSAGES messages.txt \"SELECT \* FROM ITG.{}\" < file_with_table_names | sh


Last edited by Scott; 08-04-2010 at 06:26 PM..
Sponsored Links
    #3  
Old 08-04-2010
srimitta srimitta is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 13 May 2014, 8:25 AM EDT
Location: Indianapolis
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Scott,

Thanks for the reply.

I ran script and getting below error message, any idea.


Code:
$ ksh -x export_db2_tables.ksh
+ cd /home/db2inst2/data_export/scripts/
+ cat table_names
table1
table2
table3
+ db2 connect to ITG

   Database Connection Information

 Database server        = DB2/AIX64 9.5.2
 SQL authorization ID   = DB2INST1
 Local database alias   = ITG

+ xargs -I{} db2 EXPORT TO ~/data_export/{}.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.{}"
+ 0< table_names
+ sh
sh: SQL0104N:  not found.
sh[2]: found:  not found.
sh[4]: SQL0104N:  not found.
sh[5]: found:  not found.
sh[7]: SQL0104N:  not found.
sh[8]: was:  not found.

Thanks
Srimitta

Last edited by Scott; 08-04-2010 at 06:56 PM.. Reason: Added code tags
    #4  
Old 08-04-2010
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 20 October 2014, 2:03 AM EDT
Location: Zürich
Posts: 8,484
Thanks: 332
Thanked 1,047 Times in 914 Posts
Hi.

Sorry about that


Code:
while read TABLE; do
  db2 EXPORT TO ~/data_export/$TABLE.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.$TABLE"
done < file_with_table_names

My globbing brain is not engaged! If it doesn't work, try changing * to \*
Sponsored Links
    #5  
Old 08-05-2010
srimitta srimitta is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 13 May 2014, 8:25 AM EDT
Location: Indianapolis
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Scott, Excellent it's working.

Srimitta
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Export Command chpraveen_862 Shell Programming and Scripting 3 03-19-2009 04:29 AM
awk/sed Command : Parse parameter file / send the lines to the ksh export command rajan_san Shell Programming and Scripting 4 11-06-2008 12:29 PM
Export command prakash.kudreka UNIX for Advanced & Expert Users 3 11-20-2007 07:37 AM
export command radhika03 UNIX for Dummies Questions & Answers 2 12-16-2005 08:25 AM
using export command sveera Shell Programming and Scripting 4 04-01-2005 10:05 AM



All times are GMT -4. The time now is 07:21 AM.