Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2004
    Posts
    268

    Unanswered: 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.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    For a single command:

    db2 -vz output_file "command"

    For a script:

    db2 -z output_file -tvsf script_file

    Andy

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  4. #4
    Join Date
    Oct 2004
    Posts
    268
    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.

  5. #5
    Join Date
    Oct 2004
    Posts
    268
    Never mind. -a would do it I think


    ./Myshell.sh | tee -a Result.out .............Thanks again......

  6. #6
    Join Date
    Jan 2003
    Posts
    1,605
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •