3

I have a script that contains:

db2 connect to user01
db2 describe indexes for table table_desc

What I figure is happening is the process that executes the first line is different from the process that runs the second line. This means that the process that executes the first line gets the connection while the second process that runs the second line has no connection at all. This is verified because I get an error at the second line saying that there exists no database connection.

Is it possible to have the same process run both commands? Or at least a way to "join" the first process to the second?

2
  • 3
    This may help: how to run db2 sql command from a command line? Commented Jun 19, 2013 at 14:45
  • The solution in that link doesn't really apply to what I was doing but it definitely put me on the right path. Commented Jun 19, 2013 at 17:32

1 Answer 1

7

If you want both instructions to run in the same process you need to write them to a script:

$ cat foo.db2
connect to user01
describe indexes for table table_desc

and run that script in the db2 interpreter:

db2 -f foo.db2

A Here Document might work as well:

db2 <<EOF
connect to user01
describe indexes for table table_desc
EOF

I can't test that, though, since I currently don't have a DB2 on Linux at hand.

Sign up to request clarification or add additional context in comments.

1 Comment

Both of these work great, thanks a lot! This was exactly what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.