script that switch users

I want to write a script that among other things switch users. (It runs under root)
How do I do that?
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.

Friendly advice,

More detail, more points (esp. if you want someone to write a script for you)

Meanwhile, have you looked at su?

man su

wabby26Author Commented:
This is not a script this is only one command and for that you want more points? This is an EASY question.
Didn't mean to offend you.  I don't need more points.  I was literally giving you some *friendly* advice.  

If you want someone to take the time to figure out the details you left out of your question and then write a script, you'll need to cough up more points.  Friendly types, like me, abound, and may help you write the script for 50 pts, but not many are going to beg you for more detail.

You obviously didn't even take the time to man su.  You may be able to figure it out on your own and not spend any points!

Good luck,
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Just put `/bin/su - username' in your script. The best use for this in a script is to do a particular task as that user, e.g. database backups that requires a specific user ID plus their environment.

/bin/su - oracle -c /home/oracle/backupscript > /home/oracle/backuplog

- becomes user oracle & does a backup, saving any output to a file. Such a command could be put in a cron job

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
You know the old saying:

Give a man a fish, he'll eat for the day; teach him to fish, he'll eat for life.

tfewster has learned to fish, i.e. man su

wabby26 just got a fish.  Sad :(

Well, that's why tfewster is the expert.  Good job, dude!

wabby26Author Commented:
Rob - I guess I gave enough details because this is what I needed.
10x anyway.
tfewster - 10x.
wabby - Thanks

Rob - I know what you mean, but I thought wabby might just want a quick practical example.
wabby26Author Commented:
Rob - This IS what I needed. I didn't ask to write me a program, I just asked for a one little command.
Do you really think I should spend time on looking for one command that many people already know? In that time I can do things that have more value.
You're not gonna at least let me have the last word, are you? :)

If you'll will reread your question you most certainly DID NOT ask for "one little command".  And I quote:

"... write a script that among other things ..."

I answered it as a fifty point (yes, easy) question, by pointing you to the su command.

My point was that if you want a script, it'll cost you or you won't get many bites.  I thought I was giving some helpful advice from my own experience.  I undervalued a question, once, and didn't get any help.

Anyhow, common courtesy on EE says give credit to the first one who gives the answer (whether it's a comment or proposed answer).  I pointed you to su, and you ultimately accepted su as the answer.  

There.  My chest truly feels lighter.  

Though I tend to get hyper, I really am glad you got the answer you were looking for.

Hope there are no hard feelings.

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.