Re: using sudo command to connect to Db2 database in AIX 7.3

Grant Taylor via sudo-users <[email protected]> Wed, 16 Jul 2025 22:05:26 -0500
Newsgroups gmane.comp.tools.sudo.user
Message-ID <[email protected]>
I don't know.  So the rest is me questioning and making suppositions.

On 7/13/25 10:04 PM, kousuke goto via sudo-users wrote:
> $ . /db2/insthome/[INSTANCE]/sqllib/db2profile

 From what little I know about Db2, this sets values in the current 
interactive shell.

> $ sudo -u [USER] db2 connect to [DB]

I believe this will use the values from the current environment to 
execute in a separate ephemeral environment.

My understanding is that the separate ephemeral environment itself can't 
directly effect the environment in the interactive shell.

Maybe it can modify files, but the interaction is limited.

> $ sudo -u [USER] db2 "export to /tmp/packages.txt of del select * from syscat.packages"

Since the `db2 connect` command can't (directly) modify the calling 
interactive environment, I don't see any way to pass the connection / 
authentication information from the second command to the third command 
via the interactive calling environment.

I would wonder if you could do something like this:

sudo -u [USER] "db2 connect to [DB]; export to /tmp/packages.txt of del 
select * from syscat.packages"

This runs both the `db2 connect` and `export` in the same separate 
ephemeral environment.

> They also provide me a workaround.

What is the workaround that was suggested?

Maybe that will provide some hints for us.

> But the other team I mentioned earlier want to know  if there's a 
> specific way(like configuring sudo's setting files or other aix files) 
> to make it work like the current envrionment.

What happens if you run the `db2 connect to [DB]` command directly from 
the interactive environment?  That should configure the interactive 
environment to connect to DB2 and those configurations should be 
inherited by the 3rd command in it's ephemeral environment.

> Thank you,

:-)

Please let us know what you find out.



-- 
Grant. . . .
____________________________________________________________
sudo-users mailing list <[email protected]>
For list information, options, or to unsubscribe, visit:
https://www.sudo.ws/mailman/listinfo/sudo-users