[BangPypers] Executing Commands using sudo

davidsnt davidsnt at gmail.com
Thu Nov 15 12:49:31 CET 2012

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.


1. Login to host1 as user1

## ssh user1 at 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.

Davidsanthosh L

More information about the BangPypers mailing list