tags:

views:

606

answers:

2

Hi All,

I am new to shell scripting....

Can someone give an example of running shellscript via sudo user...

I tried like this....

sudo /usr/local/sbin/deploy | ./tmp/cp1.sh

the above script is executed as a normal user not as the sudo user...

Any help is apprciated,...

With Regards, Ramesh.T

+2  A: 

With this command, the deploy script is executed under the root user, however, the ./tmp/cp1.sh script is ran by the current shell under your current privileges. To avoid this, you can prefix sudo to both:

sudo /usr/local/sbin/deploy | sudo ./tmp/cp1.sh

Or you can spawn a shell from within sudo, so the shell is already running as root:

sudo sh -c '/usr/local/sbin/deploy | ./tmp/cp1.sh'
intgr
A: 

The problem is that when you want to do that, you need to have the sudo password and be in the sudoers file, else it will fail. But you could try to use gksudo (graphical version of sudo) so when it gets called it asks for the password.

Bloeper
Hi,Thanks for the reply....Is there any other way to accomplish this without entering password...
Ramesh.T