Solved

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

Posted on 2006-11-01
3
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to calculate the current use of PVU on my TSM server. 4 108
How can i set a Environment Variable in my Unix script ? 3 92
awk sed 8 136
centos commands 6 118
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

752 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