su - pass in userid and password

How to pass in user id and password when executing 'su' command in a script?
sn8776Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jonkeCommented:
Would it not be easier to run the script as root, then at the start su to a different user- that way you wouldn't need a password.
0
jonkeCommented:
Then you would just have to 'exit' back to root, to do something as root.
0
ahoffmannCommented:
su - user

password cannot be suplied, 'cause UNIX reads passwords from tty directly. If you realy need it, you have to use expect as scripting language.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

tfewsterCommented:
ahoffman - Couldn't you use su - user < file_containing_password or is su too smart to be cheated that way?
0
ozoCommented:
su is too smart to be cheated that way
But on some systems you may be able to
chown user script
chmod u+s script
0
sn8776Author Commented:
Hi all,

I was told that i can try out using "Sticky Bit", so I think will closed this question by giving the point to ahoffmann as he is the one to proposed the answer to me and I got answer for this question from u all clearly.

I also would much appreciate if any of you can tell me more about the "sticky bit" technics and may be where I can find more information about that.

No extra point for this.

Anyway, thanks for you all to repond to my question.

from
sn
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.