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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to run non root command under root... How ?

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

we're running a server software on one of our machines that uses certain commands vor lock_server, unlock_server, stop server, etc. that can only be run by a certain non root user. It is not possible to run these commands as root...

Is there any way to write a script, that switches from root to that certain user and runs the server commands ?

How can we do it?

We tried:

/usr/bin/su - Username "-c Command"

but it didn't quite work out ...


Thanks in advance !

Regards
Thomas
 
Hi Thomas,

if you used:

/usr/bin/su - Username "-c Command"

it wouldn't work. But perhaps if you use:

/usr/bin/su - Username -c "Command"

(ie keep the -c out of the quotes), it might. Gove it a go and get back to us. Cheers.
 
hi,

One other thing to note is that if in your script you set environment vars , patch and you do su - it will run the users .profile. If you want to keep your own environment run
su Username -c "Command"


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top