1

I have a script I've setup to run a number of tasks, one of which is to set up a table in a DB and later remove it (for automated testing).

The issue comes that on only a few of the users that I use the su - user -c command, the call to db2 fails. The odd thing however, is that using su - user and then running the db2 command works fine (outside of the script). This only happens after I have run the script once and during the script running process (though there's nothing I can see that would cause it to somehow change anything, sadly I can't share the exact code, though I could share an example/recreation of it if it would help), which merely contains a few basic loops, and a bunch of su - user -c commands calling IBM mq commands.

For example this fails:

su - user -c "db2 connect to database USER user USING pass; db2 'CREATE TABLE LETABLE (LEFIELD VARCHAR (16))'"

Error:

DB21016E The Command Line Processor encountered a system error while sending the command to the backend process.
DB21018E A system error occurred. The command line processor could not continue processing.

However this works fine:

su - user
db2 connect to database USER user USING pass
db2 'CREATE TABLE LETABLE (LEFIELD VARCHAR (16))'

I've tried outputting the env command in both cases, to see if there's somehow something different, but they match as would be expected. I've also tried adjusting the order the different users run in, but that doesn't seem to help either.

I am truly confused and any help would be greatly appreciated.

I am using a ksh shell.

1
  • Apologies for the extreme delay in responding. My office blocked StackOverflow and it's been an insane effort to get it unblocked.
    – CheckovZA
    Commented Apr 24, 2015 at 14:55

2 Answers 2

1

I have a workaround that seems to work.

I created a separate ksh script that does all the db2 commands (establish a connection, then creates a table and grants permissions on it), and run that with any arguments needed.

This means that it's running a set of commands in one su instance, despite using the -c part, so as to run it inside the script effectively.

1
  • I've "accepted" this answer, though I'm not sure if that's bad form or not. If it is, please let me know, and I'll happily adjust in a way that makes more sense.
    – CheckovZA
    Commented May 11, 2015 at 13:18
0

Problem is that environment for command run using su - user and su - user -c might differ and db2 needs some missing variable e.g. DB2INSTANCE to be set in order to work correctly. Compare output of:

$ su - user
# printenv

and

$ su - user -c printenv

You can then pass missing variable simply like this:

$ su - user -c "export DB2INSTANCE=inst ; db2 connect to database USER user USING pass; db2 'CREATE TABLE LETABLE (LEFIELD VARCHAR (16))'"
1
  • The thing is, I ran that env check before, and I repeated it to make sure. Somehow, the env outputs are identical, but it still causes an issue when I run the db2 stuff.
    – CheckovZA
    Commented Apr 24, 2015 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .