If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2/Linux question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-08-08, 16:20
mdx34 mdx34 is offline
Registered User
 
Join Date: Oct 2004
Posts: 238
DB2/Linux question

Is there a way to get the output of a db2 command into BOTH screen and a file ? or it has to be one OR the other ?

This is running a DB2 command from a command line like,

db2 "Select * from myschema.mytable"

or the DB2 commands from a shell sscript.


Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-08-08, 16:44
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
For a single command:

db2 -vz output_file "command"

For a script:

db2 -z output_file -tvsf script_file

Andy
Reply With Quote
  #3 (permalink)  
Old 04-09-08, 03:36
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or you can use the "tee" command, which is exactly intended for things like that in a generic way.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 04-09-08, 08:23
mdx34 mdx34 is offline
Registered User
 
Join Date: Oct 2004
Posts: 238
Thank you both............I was leaning towards the "tee".

Since the script is a shell script with DB2 commands in it would,


./Myshell.sh | tee Result.out be Ok ?

Also, is there a way to add to output file and not replace it ?

Thanks again.
Reply With Quote
  #5 (permalink)  
Old 04-09-08, 08:57
mdx34 mdx34 is offline
Registered User
 
Join Date: Oct 2004
Posts: 238
Never mind. -a would do it I think


./Myshell.sh | tee -a Result.out .............Thanks again......
Reply With Quote
  #6 (permalink)  
Old 04-10-08, 01:27
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
db2 -r output.txt -tvf sqlfile.sql

P.S. Don't forget executing the above command twice will append new records to output file.
Hope it helps,
Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On