W
W
wawa2018-06-10 20:52:02
Python
wawa, 2018-06-10 20:52:02

Fabric: how to run sudo() in cd() context?

from invoke import task

@task
def do(c):
    with c.cd('/opt'):
        c.run('pwd')  # OK: "/opt"
        c.sudo('pwd')  # ERROR:  "sudo: cd: command not found"

I run it like this: fab -H [email protected]:port --prompt-for-sudo-password
do "cd" is not a program but a pure bash command, and c.sudo in context turns it into "sudo cd && sudo pwd". But there is no solution to come up with. Please help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question