RandomDisplayName
RandomDisplayName

Reputation: 281

is there a way to use fabric run() and sudo() at a time?

I'm trying to automate a test in python 2.7 (in eclipse on linux ubuntu 12.04). The test checks configurations on another pc, so I'm using fabric for the ssh connection.

I need to execute a script:

run("cd somepath && ./execute_script.sh")

The problem is that my script needs a sudo to run, but changing the command to this:

sudo("cd somepath && ./execute_script.sh")

does not work since "cd" doesn't work in combination with sudo. I also cannot split the command in two parts, because that would create 2 shells, and the second one would forget the path I've been going to in the first one.

If I do it like this:

run("cd somepath && sudo ./execute_script.sh")

the test wouldn't work completely automatic since you would have to enter the password at a time.

Is there a way to some sort of combine run() and sudo()?

Upvotes: 0

Views: 398

Answers (1)

Ishaan
Ishaan

Reputation: 886

How about:

from fabric.api import cd,sudo
with cd('somepath'):
    sudo('./execute_script.sh')

Upvotes: 2

Related Questions