Fabric - sudo -u

Pierre de LESPINAY picture Pierre de LESPINAY · Dec 9, 2011 · Viewed 10.5k times · Source

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 ?

Answer

mac picture mac · Dec 9, 2011

Judging from the documentation:

sudo('python manage.py collectstatic --noinput', user='www-data')