[BangPypers] Executing Commands using sudo

2012-11-15 Thread davidsnt
Hello Team,

I have a bunch of servers where I have to login as user1 and then sudo as
super user and again change to user2 and execute a bunch of commands, can
you guys help with any thought how can I get this done in python.

I tried doing it with expect but couldnt get it right.

Steps

1. Login to host1 as user1

## ssh user1@host1
[enter password for user1]

2. use sudo and become a superuser

## sudo su
[enter password for user1]

3. change to user2

##su -l user2

## execute the commands

4. Logout

I cannot login as user2 over ssh, it is not enabled.


Regards,
Davidsanthosh L
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Executing Commands using sudo

2012-11-15 Thread Vid
On Thu, Nov 15, 2012 at 6:49 AM, davidsnt  wrote:
> Hello Team,
>
> I have a bunch of servers where I have to login as user1 and then sudo as
> super user and again change to user2 and execute a bunch of commands, can
> you guys help with any thought how can I get this done in python.

Your mail is not clear about what you are attempting to do after you
login. Anyway, if you are deploying software across multiple remote
servers, "Fabric" is your friend. HTH.

Regards,
Vid  ॥ http://svaksha.com ॥
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Executing Commands using sudo

2012-11-15 Thread satyaakam goswami
On Thu, Nov 15, 2012 at 5:19 PM, davidsnt  wrote:

> Hello Team,
>
> I have a bunch of servers where I have to login as user1 and then sudo as
> super user and again change to user2 and execute a bunch of commands, can
> you guys help with any thought how can I get this done in python.
>

how many does a bunch mean ?


> 4. Logout
>
> I cannot login as user2 over ssh, it is not enabled.
>

this use case can  be done in native python or if you do not want to take
care of the nitty gritties you can take a look at
http://code.google.com/p/sshpt/ , write shell scripts around it to get it
done , this tool again is written using  python , there are other tools
depending on the complexity .

-Satya
fossevents.in
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Executing Commands using sudo

2012-11-15 Thread Rahul R
$pip install sh (http://amoffat.github.com/sh/)
pretty much does everything u asked for.

http://amoffat.github.com/sh/tutorials/2-interacting_with_processes.html


--Rahul

On Thu, Nov 15, 2012 at 10:01 PM, Vid  wrote:

> On Thu, Nov 15, 2012 at 6:49 AM, davidsnt  wrote:
> > Hello Team,
> >
> > I have a bunch of servers where I have to login as user1 and then sudo as
> > super user and again change to user2 and execute a bunch of commands, can
> > you guys help with any thought how can I get this done in python.
>
> Your mail is not clear about what you are attempting to do after you
> login. Anyway, if you are deploying software across multiple remote
> servers, "Fabric" is your friend. HTH.
>
> Regards,
> Vid  ॥ http://svaksha.com ॥
> ___
> BangPypers mailing list
> BangPypers@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Executing Commands using sudo

2012-11-15 Thread davidsnt
>>how many does a bunch mean ?

close to 7

I tried a native linux way  with ssh -t user1@host "sudo su -l user2" to
connect to the host directly as user2 but still it fails to execute the
command


Regards,
Davidsanthosh L


On Thu, Nov 15, 2012 at 10:10 PM, satyaakam goswami wrote:

> On Thu, Nov 15, 2012 at 5:19 PM, davidsnt  wrote:
>
> > Hello Team,
> >
> > I have a bunch of servers where I have to login as user1 and then sudo as
> > super user and again change to user2 and execute a bunch of commands, can
> > you guys help with any thought how can I get this done in python.
> >
>
> how many does a bunch mean ?
>
>
> > 4. Logout
> >
> > I cannot login as user2 over ssh, it is not enabled.
> >
>
> this use case can  be done in native python or if you do not want to take
> care of the nitty gritties you can take a look at
> http://code.google.com/p/sshpt/ , write shell scripts around it to get it
> done , this tool again is written using  python , there are other tools
> depending on the complexity .
>
> -Satya
> fossevents.in
> ___
> BangPypers mailing list
> BangPypers@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers