Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

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

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???
0
ICPooreman
Asked:
ICPooreman
  • 2
1 Solution
 
amit_gCommented:
Use

sudo ./mycommand args
0
 
amit_gCommented:
Or you can use

su root -c "./mycommand args"
0
 
ravenplCommented:
In fact some su are more restrictive about parameters and requires username as last param, try then
su -c "./mycommand arg arg" root
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now