Reputation: 809
I have some freebsd servers and don't have sudo. But I want to run some command automatically with root just like the following command:
def autodeploy(url):
with cd('/tmp'):
if not exists('releasetar.sh'):
put('/tmp/releasetar.sh', 'releasetar.sh', mode=0644)
run("wget '{}'".format(url))
run('su - -m -c "cd /tmp && bash /tmp/releasetar.sh"')
the su
with -c
option worked to linux but didn't worked on freebsd. How can I solved this problem ? I'm wish your solution can both worked on linux and freebsd. Thank you for your answer~~
Upvotes: 0
Views: 1332
Reputation: 5588
If you're using fabric you can just provide the -u argument from the command line to specify which user you want to run the task as
fab -u root <task name>
For more options from the command line check out http://docs.fabfile.org/en/1.7/usage/fab.html#command-line-options
You can also set your username programmatically
from fabric.api import run, settings
with settings(user="root"):
run("some-command")
Upvotes: 2