1820254 Members
2619 Online
109622 Solutions
New Discussion юеВ

su root -c command

 
SOLVED
Go to solution
Manuales
Super Advisor

su root -c command

What is the meaning of -c follows:

su root -c "$COMMAND2"

Thanks, manuales.
6 REPLIES 6
Pete Randall
Outstanding Contributor
Solution

Re: su root -c command

It means "switch user to root and execute the command specified in the variable $COMMMAND2"


Pete

Pete
Mark Greene_1
Honored Contributor

Re: su root -c command

The -c is to run a single command, as opposed to spawning a new shell environment. This is a convenient option for scripting.

mark
the future will be a lot like now, only later
James R. Ferguson
Acclaimed Contributor

Re: su root -c command

Hi Manuales:

The command says to switch the user to be "root" and then as the root user, run the command specified byt eh $COMMAND2 variable.

Since the 'su' was of the form without a hyphen, as in 'su -', the login profile of the target user (here, "root") is *not* run first, before the command ($COMMAND) is executed. See the manpages for 'su' for more information.

Regards!

...JRF...
Geoff Wild
Honored Contributor

Re: su root -c command

It is running a command - non-interactively as well...

$COMMAND2 is a command, could be a s simple as "date".

su - root -c "/usr/bin/date"

would run the command date as root (it would prompt for root password).

More common to see root running commands (no password required)

IE:

as root:

su - oracle -c "start_all.sh"

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sandman!
Honored Contributor

Re: su root -c command

"su root -c command" means execute command using the temporary environment and permissions of user root.

cheers!
Senthil Prabu.S_1
Trusted Contributor

Re: su root -c command

Hi,
su -c is used for passing a single COMMAND to the shell.

Ex;
I am a root user, wants to execute a ls command as "rtp40" user, then execute this command;

kassel1:~ # su - rtp40 -c ls
1.sh compo ctxminitool Documents MgmtBadParamCheck.java tstclasses
kassel1:~ #


HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.