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 > db2look output issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-09-09, 14:03
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
db2look output issue

I am working on a script that is based on the parm will generate a DDL using db2look. Problem I am having is I do not want anything showing up on the screen while db2look is running.

I have found a solution, but it makes no sence to me what so ever. here is where I am looking out for you folks to help me understand why it is doing what it is doing.

Here is what I am getting:

1. Running db2look piping it out to a file
Quote:
db2look -d dbname -z schema -t ADVISE_INDEX -e -nofed -noview > x
-- No userid was specified, db2look tries to use Environment variable USER
-- USER is: mmmmmm
-- Specified SCHEMA is: schema
-- The db2look utility will consider only the specified tables
-- Creating DDL for table(s)

Return code for this command is 0
DDL Information going to a file, lines with '--' are going to my screen.

2. Now I am going to try to send std out to a file and not a screen

Quote:
db2look -d dbname -z schema -t ADVISE_INDEX -e -nofed -noview > x 1>xx
-- No userid was specified, db2look tries to use Environment variable USER
-- USER is: mmmmmm
-- Specified SCHEMA is: schema
-- The db2look utility will consider only the specified tables
-- Creating DDL for table(s)

Return code is still a 0
However, as expected my x file is empty and all of the info is in the xx file. But garbage still went to the screen.

3. My fingers did their own walking and wrote this

Quote:
db2look -d fctdbp -z uszaqk3 -t ADVISE_INDEX -e -nofed -noview >x 2>xx

Return code is still a 0
This gave me exactly what I need. DDL into a file, garbage in a dumpster.

Here is where my dilemma. Why all those lines with '--' are treated as an error While return code is still a BIG FAT ZERO? I would have never guessed it.

BTW. I am going to run sed command to clean up garbage file and then run a check on it. If it is empty, then there were no errors, if it is not empty...well, you guessed.

Thank you and remember. It is Friday and it is 5pm someplace. But don't ignore my question
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #2 (permalink)  
Old 10-09-09, 15:18
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
but lines that begin with '--' are just comments, not errors.
Reply With Quote
  #3 (permalink)  
Old 10-09-09, 16:08
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
He means that those messages are being written to stderr and not stdout as one would expect. Why IBM chose to do that is beyond me. You will have to ask them as to their reasoning.

Andy
Reply With Quote
  #4 (permalink)  
Old 10-09-09, 16:36
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
This is standard practice to write the "payload" output to stdout and diagnostic messages to stderr so as not to mix two types of information. Many unix utilities work that way.
Reply With Quote
  #5 (permalink)  
Old 10-09-09, 16:55
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Bella, Andy is right on the money on what I meant. Bella, can you go smack someone over there for me?

Nick, if you are correct, then it is madness. If I haven't discovered that it is putting -- into the stderr and was performing an error check. It would be alarming on every entree even so there was no problem.

Not doubting you, but can you please provide some kind of document that talks about it. I have been reading UNIX book all day on it and haven't found a single references on this practice.

BTW. It does write this junk to stdout anyway.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #6 (permalink)  
Old 10-09-09, 17:46
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
I think I got it now. You expect stderr to return a non-zero RC if the file contains something. If I specify a non-existing db name, then the RC is non-zero and the file contains the same comments plus the error message.
Reply With Quote
  #7 (permalink)  
Old 10-09-09, 18:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Cougar8000

Nick, if you are correct, then it is madness.
If you say so.

Shell exit code is for status checks. Different output streams are used to separate program main output and diagnostic messages.

Quote:
Originally Posted by Cougar8000
Not doubting you, but can you please provide some kind of document that talks about it.
Certainly. Amazon.com: Unix Programming Environment (Prentice-Hall Software Series) (9780139376818): Brian W. Kernighan, Rob Pike: Books
Reply With Quote
  #8 (permalink)  
Old 10-12-09, 09:41
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
I will get this book, but mean while. Following what you are saying dashes should only go to stderr, why do they show up in stdout as well?
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #9 (permalink)  
Old 10-12-09, 11:26
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The default stream for stderr goes to the console, unless you redirect it with 2> ...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #10 (permalink)  
Old 10-12-09, 11:50
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Knut, I understand and know this. My point is. If dashes are treated as stderr, why do they still show up in stdout even so I do redirect it with 2>

This tells me that they are treated as stdout as well as stderr. And that is what drives me nuts I have enough problems my own split personality
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
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