[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fab-user] sudo with user=...: can't read MY bash profile or change to M
From: |
Shenton, Chris (HQ-LM020)[InDyne, Inc] |
Subject: |
[Fab-user] sudo with user=...: can't read MY bash profile or change to MY dir |
Date: |
Thu, 12 Aug 2010 10:44:11 -0500 |
I'm a fabric newbie so perhaps not using it right. I'm trying to use sudo()
and setting the user= parameter to postgres or other applications users. It
appears to want to source MY own ~/.bash_profile, which generates harmless but
annoying errors. If I say use the shell=False parameter it fail when it
automatically tries to change to MY own home directory. Having no shell also
prevents actions like 'cd' and 'source' from working, which I need to activate
virtual environments.
The first example's doing postgres and things actually work OK here, because it
doesn't need to be in any particular directory. But I'd like to get rid of the
distracting error messages:
> def sudo_cd_wrapper():
> with cd("/tmp"):
> sudo("whoami && pwd")
> sudo("whoami && pwd", user="postgres")
> sudo("whoami && pwd", user="postgres", shell=False)
> sudo("psql -l -t", user="postgres", shell=False)
>
$ fab -f fabsudo.py sudo_cd_wrapper -H evps1
[evps1] sudo: whoami && pwd
[evps1] out: root
[evps1] out: /tmp
[evps1] sudo: whoami && pwd
[evps1] err: /bin/bash: /home/cshenton/.bash_profile: Permission denied
[evps1] out: postgres
[evps1] out: /tmp
[evps1] sudo: whoami && pwd
[evps1] out: postgres
[evps1] out: /home/cshenton
[evps1] sudo: psql -l -t
[evps1] err: could not change directory to "/home/cshenton"
[evps1] out: nasascience | nasascience | UTF8
[evps1] out: postgres | postgres | UTF8
The second example's doing django in a virtual env and the first works (with an
annoying error msg) but the second one fails since the 'source' command is not
available without a shell:
> def sudo_venv():
> with cd("/insts/nasascience"):
> sudo("source .virtualenv/bin/activate && django-admin.py validate",
> user="nasascience")
> sudo("source .virtualenv/bin/activate && django-admin.py validate",
> user="nasascience", shell=False)
$ fab -f fabsudo.py sudo_venv -H evps1
[evps1] sudo: source .virtualenv/bin/activate && django-admin.py validate
[evps1] err: /bin/bash: /home/cshenton/.bash_profile: Permission denied
[evps1] out: 0 errors found
[evps1] sudo: source .virtualenv/bin/activate && django-admin.py validate
[evps1] err: sudo: source: command not found
Fatal error: sudo() encountered an error (return code 1) while executing
'source .virtualenv/bin/activate && django-admin.py validate'
Aborting.
Any thought on how to suppress the error messages or get it to change into the
target user's homedir?
Perhaps I'm being naive, but I would think that if sudo() specifies a "user="
parameter that on the remote server it should change to the directory of the
specified user and set HOME to it before executing the command, like
sudo -H -u username pwd
would do.
Thanks for your help... and for fabric :-)
- [Fab-user] sudo with user=...: can't read MY bash profile or change to MY dir,
Shenton, Chris (HQ-LM020)[InDyne, Inc] <=