Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabric - sudo -u

I'm using fabric to launch a command on a remote server.
I'd like to launch this command as a different user (neither the one connected nor root).

def colstat():
  run('python manage.py collectstatic --noinput')

Trying

def colstat():
  sudo('-u www-data python manage.py collectstatic --noinput')

Oviously this won't work because -u will be considered as a command and not an option of sudo

out: /bin/bash: -u : command not found

(www-data is the user which should run the command)
How can I use www-data to run my command from Fabric ?

like image 791
Pierre de LESPINAY Avatar asked Dec 09 '11 12:12

Pierre de LESPINAY


People also ask

What is fabric tool used for?

Fabric is a Python library (i.e. a tool to build on) used for interacting with SSH and computer systems [easily] to automate a wide range of tasks, varying from application deployment to general system administration.

What are fabfiles?

Fab Files do exactly as they say - they're files and they're fabulous! These files are mainly designed for storing photos and notes, but if you've got paper or card scraps that you'd like to keep hold of, they can stashed inside too. With a variety of sizes on offer, there'll be something to suit you and your needs!

What is fabric fab?

Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python objects in return.

How do you answer prompts automatically with Python fabric?

The section about Prompts in the Fabric documentation says: The prompts dictionary allows users to control interactive prompts. If a key in the dictionary is found in a command's standard output stream, Fabric will automatically answer with the corresponding dictionary value.


1 Answers

Judging from the documentation:

sudo('python manage.py collectstatic --noinput', user='www-data')
like image 83
mac Avatar answered Oct 09 '22 20:10

mac