Operating System - HP-UX
1855740 Members
5692 Online
104103 Solutions
New Discussion

Passing value to su(switch user) cmd

 
diwakar_4
Frequent Advisor

Passing value to su(switch user) cmd

Hi All,

I want to write one script which change user for me without prompting for any inputs.
*******************************************
changeuser.sh:

echo " user is going to change to rpjms "
su rpjms

echo " User has been chnaged successfully "
********************************************

It should not as for password. I want to pass password in script itself.

Could some one help me to do this?

Thanks

6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: Passing value to su(switch user) cmd

Shalom,

/bin/su - oracle -c "command value with parameters"

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
OFC_EDM
Respected Contributor

Re: Passing value to su(switch user) cmd

Look at the sudo command as well. You'll have to download and install as it doesn't come with the OS.

It allows you to run commands as a specific users.

You can also control which commands you're allowed to run as that user.

The Devil is in the detail.
diwakar_4
Frequent Advisor

Re: Passing value to su(switch user) cmd

Hi Steven,

i am not getting. What is meant for oracle and -c.
My user name is rpjms and password is xyz.

Thanks
Sandeep_Chaudhary
Trusted Contributor

Re: Passing value to su(switch user) cmd

install sudo. It is free ware.

configure /etc/sudoers file. either
vi /etc/sudoers OR
visudo

sample:

Host_Alias IS_SAP=suxde03*

# User alias specification
User_Alias UNIX_TEAM=arpdh, neumannl, rau, rojahn, sandchau
Cmnd_Alias SUROOT=/usr/bin/su -, /usr/bin/su - root
UNIX_TEAM IS_SAP=(ALL) NOPASSWD: ALL
Steven E. Protter
Exalted Contributor

Re: Passing value to su(switch user) cmd

There is an su syntax

What I gave was an example:

su - username -c "command string"

example

su - oracle -c "/sbin/init.d/oracle start"

This command says use the user profile of oracle WITH its environment and use the startup script for oracle (which I wrote) with the start parameter.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: Passing value to su(switch user) cmd

>I want to write one script which change user for me without prompting for any inputs.

Only root can do that. And after the script exits, it's back to the original user.

I suppose your script can use sudo to switch to root and then open another terminal window so you can then be the other user.
(If you don't use sudo, you might be able to use expect and then open another window?)