Operating System - HP-UX
1755046 Members
2965 Online
108828 Solutions
New Discussion юеВ

su newuser password in shell script

 
Richard Marshall
Occasional Contributor

su newuser password in shell script

How do I supply the newuser password when I do a
su - newuser in my shell script.

The script is started under my username and I want to su to the application user account within my shell script but I'm not sure how to input the newuser password.
Thanks
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: su newuser password in shell script

Hi Richard:

This isn't possible in pure shell script. The 'su' expects to offer you an interactive query for the password.

Regards!

...JRF...

Edward Alfert_2
Respected Contributor

Re: su newuser password in shell script

Can't be done... only if you are currently root does it not as you for password

http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x9fd0f841489fd4118fef0090279cd0f9,00.html
"Do what you love and you will never work a day in your life." - Confucius
Deshpande Prashant
Honored Contributor

Re: su newuser password in shell script

Hi
Su being interactive, noluck for normal user to login in to another users.
Try some suid programs instead.

If you are suing to app id to run app. programs only, why not set suid on that program.

Prashant.
Take it as it comes.
Volker Borowski
Honored Contributor

Re: su newuser password in shell script

Richard,

I do not think this is possible with "su".

Try rexec, remsh or rlogin "localhost" !

There are several ways to authenticate without a password for these programs. I favor rexec with a .netrc file for this.

Keep in mind, that you might need to call a script, that sources the profiles/loginscripts first, because rexec and remsh do not do this.

Hope this helps
Volker
G. Vrijhoeven
Honored Contributor

Re: su newuser password in shell script

MP,

you might want to try working with a simular GID. I suppose that is what there are intended for. If you have problems whith env. settings you can add the env in the script you are runnen. If thats not possible i suggest an r.... command.

Good luck

Gideon
Wodisch
Honored Contributor

Re: su newuser password in shell script

Hello Richard,

get yourself a copy of "expect" installed.
Then you can issue that password through "expect".
That's the only (simple) way I can think of (at 00:17h
at night ;-).

HTH,
Wodisch