We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

su user -c command -args doesn't accept arguments

ICPooreman
ICPooreman asked
on
Medium Priority
435 Views
Last Modified: 2010-04-21
I'm new with shell scripting so I may be missing something easy.  I'm writing a shell script which I want to su to a different user in my case the root user.  The problem is that when I do that it takes control away from the script.  Basically all I need to do is run one command as the root user so I decided I could write

su root -c ./mycommand args

which doesn't take control away from the script however mycommand now doesn't get the args I pass it.  What can I do to fix this???
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
Use

sudo ./mycommand args
CERTIFIED EXPERT
Top Expert 2006
Commented:
Or you can use

su root -c "./mycommand args"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2005

Commented:
In fact some su are more restrictive about parameters and requires username as last param, try then
su -c "./mycommand arg arg" root
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.