I am using the su - <username> in my script to change to a different user, but the password prompt comes up after the script executed the su command. How do I pass the user password to the prompt from the same script?
) to manage the session to some point. That's rarely necessary.
The man page for su on your system may give you other options of interest.
If you'd rather avoid the prompt entirely, you can use a suid program instead, or the "sudo" program can be used. The functionality of sudo may be called something different on your platform- on SCO it's "asroot", Unixware has the same concept administered through "tfadmin" and "adminuser".
BTWE, I assumed that you wanted to su to root, in part of my answer above, but the rest of it applies to any username.
Tony Lawrence
SCO Unix/Linux Resources
Actually, I need to "su - <username>" to different userid and execute the .profile in order to execute a script that, normally, would run ok when log in manually as that user but failed to run as a crontab job.
I will ask our administrator to see if the sudoer can be set up.
are you saying you can su -username -c in a script?? I don't think you can do that withouth the help of a language like expect because you'll be prompted for a password , however sudo can execute a command or a script from within a script by doing it like this:
thanks, thats what I thought the only way I know to "automate" su in a script is with using expect thought I might have missed the boat or something
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.