[BangPypers] Multilevel SSH in Python

davidsnt davidsnt at gmail.com
Tue Oct 16 13:58:09 CEST 2012


paramiko doesnt looks like a best solution as exec_command('') returns
a stdin output instead of what I wanted



import paramiko, base64
    key = paramiko.RSAKey(data=base64.decodestring('AAA...'))
    client = paramiko.SSHClient()
    client.get_host_keys().add('ssh.example.com', 'ssh-rsa', key)
    client.connect('ssh.example.com', username='strongbad', password='thecheat')
    stdin, stdout, stderr = client.exec_command('ls')
    for line in stdout:
        print '... ' + line.strip('\n')
    client.close()


Thanks,
David

On Tue, Oct 16, 2012 at 5:16 PM, Bibhas Ch Debnath <me at bibhas.in> wrote:

> Something using Paramiko[1] maybe? (I've never tried.)
>
> [1]: https://github.com/paramiko/paramiko/
>
> ----
> Bibhas
> http://bibhas.in
>
>
>
> On 16 October 2012 17:06, davidsnt <davidsnt at gmail.com> wrote:
>
> > Thank you for the quick response.
> >
> > nc and proxycommand are more of a linux way of doing it, but is there any
> > python oriented way, like I do an ssh and get an object with that I again
> > do once more ssh etc,
> >
> > Regards,
> > Davidsanthosh L
> >
> >
> > On Tue, Oct 16, 2012 at 4:56 PM, Noufal Ibrahim <noufal at nibrahim.net.in
> > >wrote:
> >
> > > davidsnt <davidsnt at gmail.com> writes:
> > >
> > > > Hello Team.
> > > >
> > > > I need some help in building a multilevel ssh program in Python.
> > > >
> > > > My requirement is that I have to connect to ServerA and from ServerA
> > > > connect to ServerB and from ServerB connect to ServerC and execute
> few
> > > set
> > > > of commands and collect the results.
> > > >
> > > > I dont have direct access to ServerB or ServerC only from ServerA I
> can
> > > > move on to ServerB and then on to ServerC.
> > >
> > > The regular ssh command has a proxycommand directive which you can use
> > > to ssh through multiple hosts similar to what you need
> > >
> > >
> >
> http://serverfault.com/questions/368266/ssh-through-multiple-hosts-using-proxycommand#368267
> > >
> > > I think you should be able to reuse this rather than write all the
> stuff
> > > yourself.
> > > [...]
> > >
> > >
> > > --
> > > Cordially,
> > > Noufal
> > > http://nibrahim.net.in
> > > _______________________________________________
> > > BangPypers mailing list
> > > BangPypers at python.org
> > > http://mail.python.org/mailman/listinfo/bangpypers
> > >
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > http://mail.python.org/mailman/listinfo/bangpypers
> >
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list