Discussion:
[Fab-user] How to switch to a account and run some commands.
santosh kumar
2017-01-09 08:06:05 UTC
Permalink
All,

I have a requirement where i need to do the following.

#su - oracle
once logged in as user oracle need to run some commands from there
$ id
$ whoami

so i can achieve this in shell in this formate

ssh <hostname> 'su - oracle' <<EOF
id
whoami
EOF

Please do let me know how can i achieve this on multiple nodes.

Thanks,
santosh D
Carlos García
2017-01-09 09:26:17 UTC
Permalink
Hi santosh,

can you use sudo on the target host? I think it’s the easiest way:

from fabric.api import sudo

sudo('id', user='oracle')
sudo('whoami', user='oracle')

If not, you should run:

from fabric.api import run

run('su - oracle -c id')
run('su - oracle -c whoami')

To ease its usage you can create a context manager, similar to prefix()
<http://docs.fabfile.org/en/1.13/api/core/context_managers.html#fabric.context_managers.prefix>,
but you will have to handle the way to pass the oracle password.

Regards

2017-01-09 9:06 GMT+01:00 santosh kumar <***@gmail.com>:

All,
Post by santosh kumar
I have a requirement where i need to do the following.
#su - oracle
once logged in as user oracle need to run some commands from there
$ id
$ whoami
so i can achieve this in shell in this formate
ssh <hostname> 'su - oracle' <<EOF
id
whoami
EOF
Please do let me know how can i achieve this on multiple nodes.
Thanks,
santosh D
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
​
santosh kumar
2017-01-09 09:51:18 UTC
Permalink
Thanks you Carols. Let me work on it and get back if i have any other
queries.

On Mon, Jan 9, 2017 at 2:56 PM, Carlos García <
Post by Carlos García
Hi santosh,
from fabric.api import sudo
sudo('id', user='oracle')
sudo('whoami', user='oracle')
from fabric.api import run
run('su - oracle -c id')
run('su - oracle -c whoami')
To ease its usage you can create a context manager, similar to prefix()
<http://docs.fabfile.org/en/1.13/api/core/context_managers.html#fabric.context_managers.prefix>,
but you will have to handle the way to pass the oracle password.
Regards
All,
Post by santosh kumar
I have a requirement where i need to do the following.
#su - oracle
once logged in as user oracle need to run some commands from there
$ id
$ whoami
so i can achieve this in shell in this formate
ssh <hostname> 'su - oracle' <<EOF
id
whoami
EOF
Please do let me know how can i achieve this on multiple nodes.
Thanks,
santosh D
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
​
Loading...