Operating System - HP-UX
1748183 Members
3410 Online
108759 Solutions
New Discussion юеВ

help with sudo and a user profile

 

help with sudo and a user profile

I am trying to replace su with sudo. I am running sudo 1.6.6 and have successfully configured the sudoers file.

My problem is that I need the same environment that I get with su.

Example:

su - oracle

this setups a host of oracle environment variables for the dba. Using sudo -u oracle does not set up these variables. I have tries the -H, -s, env -i options with out success.

Can anyone help?

Thanks
6 REPLIES 6
James A. Donovan
Honored Contributor

Re: help with sudo and a user profile

Setup a command alias

Cmnd_Alias SUORACLE = /usr/bin/su oracle, /usr/bin/su - oracle

then assign that alias to whatever user you want.

The users assigned the alias will be able to login as oracle with the appropriate environment set.
Remember, wherever you go, there you are...
Bill Douglass
Esteemed Contributor

Re: help with sudo and a user profile

If you don't want to give users a full shellas oracle, then set up a script with the appropriate environment variables in it. Then source the script before running any oracle commands:

. /home/oracle/setenv.sh

If you do this often, then you can source it from your .profile .

Jairo Campana
Trusted Contributor

Re: help with sudo and a user profile

soon of cmd_alias...
User_Alias EXAMPLE = nobody, peter, frank
....
...

write:
EXAMPLE ALL = NOPASSWD: SUORACLE
legionx

Re: help with sudo and a user profile

Hi all,

Thanks for the replies but none are answering my question. I do not need a command alias for "su". What I need is a way to run the .profile or get the environment setup by the .profile when a dba runs "sudo" to become oracle. The basic command is:

$ sudo -u oracle

I have tried sourcing the .profile with the following option
env -i ENV=/home/oracle/.profile

This did not work. I have an alias for for this I just can't get the environment.
Dhanish_3
New Member

Re: help with sudo and a user profile

have u tried
sudo su - oracle

Cheers

Re: help with sudo and a user profile

I want to thank everyone for trying to help. I got help from the sudo community that solved my problem.

As an fyi here is the solution:

sudo -H -u oracle8 env -i ENV=/opt/oracle8/product/8.1.7/ora-prof ksh

Where ora-prof simply does a . /opt/oracle8/product/8.1.7/.profile

Thanks again,

Stephen