Solved

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

Posted on 2006-11-01
3
323 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???
0
Comment
Question by:ICPooreman
  • 2
3 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 17851459
Use

sudo ./mycommand args
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 17851500
Or you can use

su root -c "./mycommand args"
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17851522
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux : adding the new user with password option, 11 106
ftpcommand 2 59
cron job says it ran, no results 25 118
Using gawk to read and manipulate multiple texts from a file 1 59
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now