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 > Piping the output of a CLP command into another command, No connection error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-01-12, 04:51
raccoon raccoon is offline
Registered User
 
Join Date: Sep 2011
Posts: 6
Piping the output of a CLP command into another command, No connection error

Hi, dear all
I have the following problem. Wondering who could tell me why it happens.

$ db2 connect to dbname
$ hoge=`db2 -x values current date | sed 's/\///g'`
$ echo $hoge
SQL1024N A database connection does not exist. SQLSTATE=08003



And it's OK when:

$ db2 connect to dbname
$ db2 -x values current date | sed 's/\///g' > result.log
$ cat result.log
01022012

Thank you.
Reply With Quote
  #2 (permalink)  
Old 02-01-12, 05:03
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
correct
some commands use sub-shell and loose the connection
this is also different in bash and ksh and even between different versions in ksh
the linux doc recommends NOT using anymore aa=`command....`
we had the same problem while upgrading ksh and had to down-grade ksh again
look at linux doc for this..
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 02-01-12, 06:05
lelle12 lelle12 is offline
Registered User
 
Join Date: Mar 2003
Posts: 86
Quote:
Originally Posted by raccoon View Post
Hi, dear all
I have the following problem. Wondering who could tell me why it happens.

$ db2 connect to dbname
$ hoge=`db2 -x values current date | sed 's/\///g'`
$ echo $hoge
SQL1024N A database connection does not exist. SQLSTATE=08003
The error is due to the pipe to sed. You can avoid error by defering sed until later:

$ db2 connect to dbname
$ h=`db2 -x values current date`
$ hoge=`echo $h | sed -e "s/\///g"`


/Lennart
Reply With Quote
  #4 (permalink)  
Old 02-01-12, 06:28
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by przytula_guy View Post
some commands use sub-shell and loose the connection
There is the ugly bypass Ugly bypass, is there a better solution?
Reply With Quote
  #5 (permalink)  
Old 02-01-12, 19:44
raccoon raccoon is offline
Registered User
 
Join Date: Sep 2011
Posts: 6
Quote:
Originally Posted by przytula_guy View Post
correct
some commands use sub-shell and loose the connection
this is also different in bash and ksh and even between different versions in ksh
the linux doc recommends NOT using anymore aa=`command....`
we had the same problem while upgrading ksh and had to down-grade ksh again
look at linux doc for this..
Thank you very much.
Not using aa=`command....` is the best choice for me ..
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