Operating System - HP-UX
1834926 Members
2850 Online
110071 Solutions
New Discussion

Re: How to switch user by script?

 
Periandro Saraiva Vaz
Occasional Contributor

How to switch user by script?

Hi friends!

I'm needing to do a script to switch user during a session without inform a password.

I've already tried to use expect, but there's a problem:
I don't get work interactive in new passord, because expect nedd a answer for each action.

Example:

$ expect
expect1.1> spawn su - i67844
spawn su - i67844
17383

expect1.2> expect "Password:"
Password: expect1.3> send "nova2002\r"

expect1.3> exit

So, when i go out of expect, I don't get to switch user.

I hope that you understand me.

Thank you!!!
Periandro Saraiva Vaz
5 REPLIES 5
Ralph Grothe
Honored Contributor

Re: How to switch user by script?

If you are willing to do your stuff with Perl it would be as easy as assignments to the special vars that represent EUID, UID, EGID, GID
(read "perldoc perlvar")

e.g.

$> = $<;

or

($>, $<) = ($<, $>);


$> # is EUID
$< # is UID
$) # is EGID
$( # is GID

(or "use English", see "perldoc English")

...provided you started your script with sufficient privileges (or have it run with suid bit set).

You also can easily fork() and exec() where you swap IDs for the child to restrict possible damage.

Read "perldoc perlipc"

Btw, there is even an Expect.pm at CPAN
http://www.cpan.org/modules/by-module/Expect/

Madness, thy name is system administration
harry d brown jr
Honored Contributor

Re: How to switch user by script?


have you tried "sudo" ??

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/sudo-1.6.6/

live free or die
harry
Live Free or Die
Periandro Saraiva Vaz
Occasional Contributor

Re: How to switch user by script?

Hi Harry,

I didn't try to use a sudo because I don't know it. Do you have an example to solve my problem?

Is there a way to solve using a table of "user's equivalence"?
Bill Cahill
New Member

Re: How to switch user by script?

If you enable the second user to be remsh'd, then you can use that.

For second user, in .rhosts add
hostname username

Then in your script, remsh to your own hostname as the second user.

eg: rlogin `hostname` -l seconduser


We use this to let oracle become applmgr in our oracle financials environment. This is acceptable because oracle is a "higher" privileged user than applmgr.
harry d brown jr
Honored Contributor

Re: How to switch user by script?

Periandro,

http://www.onlamp.com/lpt/a/2704

live free or die
harry
Live Free or Die