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 ?
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.
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!
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.
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.
Judging from the documentation:
sudo('python manage.py collectstatic --noinput', user='www-data')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With