Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using su with -c option

Status
Not open for further replies.

osu250

Programmer
Sep 27, 2004
7
0
0
US
I need to run a script that su's to diff user and then runs a command as the second user. I think the way to do this is using -c option on su but I can't seem to get it to work. Can anyone provide me with sample code / syntax ?

I am running Red Hat Linux
Thanks in advance!
 
su UserName -c "command to execute"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Keep in mind the su - <user> and su <user>

Excerpts from man page for su

If the first argument to su is a ``-'', the environment is changed to what would be expected if the user actually logged in as the specified user. This is done by invoking the program used as the shell with an arg0 value whose first character is ``-'', thus causing first the system's profile (/etc/profile) and then the specified user's profile (.profile in the new $HOME directory) to be executed.

 
cdlvj makes a good point and this is particularly important when setting up cron jobs - see the myriad questions in these fora concerning that issue!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top