Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

db2cmd in a remote session

$
0
0
Hello there,

I have a Unix shell-script that uses ssh to connect with a windows machine / cygwin and runs a script there.
At some point, I have to write some data in a DB2-DB and it goes like this:

Code:

ssh user@host "
...
...
db2cmd -i -w <<EOF 1>>$logpath/log.log 2>>$logpath/error.log
db2 CONNECT TO database USER testuser USING topsecret
db2 Insert into schema.tab values (1)
EOF
...
...

"

This doesn't work :-(
The "output" of the db2cmd seems to get lost in the layers of connections (ssh, db2cmd-"window"). The error.log is empty and log.log just contains the Windows-path (E:\sshprofiles\user) and vi says "Incomplete last line" so there isn't much to read from it.
(I am not so sure about the -i -w part but only these parameters seem to work in the last example)

I tried an interactive ssh-session (without the "..."):

Code:

ssh user@host
db2cmd -i -w <<EOF 1>>$logpath/log.log 2>>$logpath/error.log
db2 CONNECT TO database USER testuser USING topsecret
db2 Insert into schema.tab values (1)
EOF

This doesn't seem to do anything neither.

However, when I open an interactive ssh-session and run db2cmd in the active session (without the <<EOF), the insert is successful:
Code:

ssh user@host
...
db2cmd -i -w # this opens the DB2-Command window and now I'm in E:\sshprofiles\user. There I can run the SQL commands:
db2 connect to database USER testuser USING topsecret # connection to the DB was successful
db2 insert into schema.tab values (1) # value is written in the table
exit # back to the cygwin shell
exit # back to where I called the outer script



Now this is where I am really losing it:
I tried it with another machine (ssh user@host2) and ran into the same problems.
However, when I use a simple procedure to do the insert, it's working in batch-mode (with the EOF) on "host2" but not so on "host"
Code:

ssh user@host2 "
...
db2cmd -i -w
db2 connect to database USER testuser USING topsecret
db2 call schema.proc_ins(1234)
EOF
"

This works on host2, but not on with the other machine.

Probably something is up with the ODBC set-up on "host". I'd really appreciate any suggestions what I could do about this! :beer:


This is the procedure I used:
Code:

CREATE PROCEDURE schema.proc_ins (
  Arg_SQL_Name        int
  )
LANGUAGE SQL
BEGIN
  DECLARE EXIT_MESSAGE CHAR(70);
  DECLARE STATUS INTEGER DEFAULT 0;
        IF        Arg_SQL_Name IS NULL
          THEN        SET EXIT_MESSAGE='missing value';
                SET STATUS=-1;
        ELSE       
                INSERT INTO schema.tab(c1)
                VALUES(Arg_SQL_Name)
                ;
          END IF;
  IF STATUS = -1 THEN
      SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT=EXIT_MESSAGE;
  END IF;
END


Viewing all articles
Browse latest Browse all 13329

Trending Articles