18

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 ?

Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
  • Worth noticing that I think an application should not require sudo privilege. I think we should always be able to deal with stuff like ACLs. – Pierre de LESPINAY Oct 24 '13 at 09:07

1 Answers1

44

Judging from the documentation:

sudo('python manage.py collectstatic --noinput', user='www-data')
mac
  • 42,153
  • 26
  • 121
  • 131
  • 1
    Thank you, I didn't see [this part](http://docs.fabfile.org/en/1.3.3/api/core/operations.html?highlight=sudo#fabric.operations.sudo) in the doc. Especially since it's documented with almost my example case :( Sorry – Pierre de LESPINAY Dec 09 '11 at 12:55