SSH, remote login, and command output

Alex Martelli aleaxit at yahoo.com
Sun Mar 26 10:21:23 EST 2006


Spire 01 <spire01 at hotmail.com> wrote:

> Greetings!
> 
> I'm working on a Python program for a small LAN of Linux systems running
> Gentoo, and I need a little help figuring out what I need to do it.  So what
> I'd like to do is, from any given computer, log on to every other computer,
> run a certain command (which normally outputs text to the terminal), and
> store the output so I can use the aggregate statistics later in the program.

OK...

>   I would normally something along the lines of SSH to do it, but I don't
> know what I would need to pull that off in Python.  There's also one 

SSH is a good protocol, and a good Python implementation of that is
Paramiko, http://www.lag.net/paramiko/ .  Twisted also includes SSH
protocol implementations, and it's a great way to do networking.

> complication: the systems could be Gentoo systems, or they could be logged
> into Windows since they're dual booted.  Considering all of this, can anyone

There are sshd (ssh-server) implementations for Windows, though I have
no experience installing those -- you'll have to download the free ones
and give them a try.  Alternatively, you might write a Twisted-based SSH
server in Python, though, from what I recall, making Windows Services
with Python, while possible, isn't quite trivial.

Once you're SSH-connected to a machine and don't know whether it's on
Windows or Linux, it shouldn't be hard to find out -- just run a command
that gives different output in each case, and proceed accordingly.

> give me some recommendation as to what library I should learn how to use to
> pull this off? I admit, I haven't done too much in the way of networks, but
> if someone can tell me what I need to do remote logins in this way, I'll do
> what I can to make it work.

Twisted may be a bit heavy going if you have no network programming
experience, so I suggest you first try ensuring all machines have sshd
(==are able to accept SSH logins) and set up the needed passwords (for
Unix and MacOSX, this means running ssh-keygen once, placing the public
key in the .ssh directory right under the home of the user to which
you'll be logging in remotely on each machine, and the private key in
the machine you'll be logging in _from_ -- not sure how the various sshd
implementations for Windows work) -- trying it all with the ssh client
from the command line first, and then moving to paramiko.

Twisted would ensure better scalability, but if the LAN _stays_ small
that may in fact not matter.


Alex



More information about the Python-list mailing list