Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2011
    Posts
    6

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

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    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
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Mar 2003
    Posts
    280
    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

  4. #4
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    Quote Originally Posted by przytula_guy View Post
    some commands use sub-shell and loose the connection
    There is the ugly bypass http://www.dbforums.com/db2/1637290-...-solution.html

  5. #5
    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 ..

Posting Permissions

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