Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2014
    Posts
    4

    Unanswered: Db2 query on other host

    Hello,

    i need some help with a script. I made a script, which connect to different hosts to get some informations. But i got now some problems with getting informations of a database (db2) which is on a other host. I tried something like
    Code:
    var=$(rsh HOST su - db2adm -c "db2 connect to database; db2 "select * from table where DATA on ('InfoA','InfoB')"")

    if i use the commands (one by one) on the host it works...but i cant use it as "remote"-command...its like he is doing the first part but he cant do the second...can someone help me??

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Remote database connections will need a username and password.

    Andy

  3. #3
    Join Date
    Oct 2014
    Posts
    4
    Quote Originally Posted by ARWinner View Post
    Remote database connections will need a username and password.

    Andy

    i dont think its needed because i can make the connection with the first part of the command...
    Code:
    var=$(rsh HOST su - db2adm -c db2 connect to database)
    i can connect to the database with this...the only problem is that he close the connection/logg out as the user before he send the query...and thats why i want to know how i need to write it that he send both command before he logg of as the user/close the connection...but still...could you write an example for it?! :P

  4. #4
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    where DATA on ('InfoA','InfoB')"" I presume data in..
    what is the sqlcode you get : no connect ?
    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

  5. #5
    Join Date
    Oct 2014
    Posts
    4
    Quote Originally Posted by przytula_guy View Post
    where DATA on ('InfoA','InfoB')"" I presume data in..
    you are right...i wrote it wrong in this thread

    Quote Originally Posted by przytula_guy View Post
    what is the sqlcode you get : no connect ?
    ksh: db2: not found.

    i get the same msg if i write the command with an other (no db2) user

  6. #6
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    is db2adm the instance owner ? su - db2admin should execute the profile
    you can also force the execution of profile to set the environment
    maybe better to create a script at target system and execute this script instead of individual commands
    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

  7. #7
    Join Date
    Oct 2014
    Posts
    4
    Quote Originally Posted by przytula_guy View Post
    is db2adm the instance owner ? su - db2admin should execute the profile
    you can also force the execution of profile to set the environment
    maybe better to create a script at target system and execute this script instead of individual commands

    Yes he is the owner...the first command does work with that user...he can connect to the database...but the query doesnt work because (it seems like that) he try it as the wrong user or he disconnect and tries to do the second command on the "local" host where the user doesnt exist

  8. #8
    Join Date
    Nov 2011
    Posts
    334
    hi, Cyver

    plz try this :

    var=$(rsh HOST su - db2adm -c "db2 connect to database; db2 \"select * from table where DATA on ('InfoA','InfoB')\"")

  9. #9
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    what about having a script on your other server, that you then just execute?
    Dave

Posting Permissions

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