timing out an ssh command

Paul Swartz z3p at twistedmatrix.com
Thu May 8 14:35:31 EDT 2003


"Andrei Doicin" <Andrei.Doicin at cern.ch> wrote in message news:<b9d72v$kcm$1 at sunnews.cern.ch>...
> Hi,
> 
> I've had a brief look at "twisted", and it certainly seems powerful,
> although a new learning curve I'd like to avoid, in
> order to stay "on the path" with Python ... so to speak.

Twisted isn't off the path, it's written almost entirely in Python :)

< some code cut>
> def the_command():
>     payload = string.join(sys.argv[1:])
>     sshcmd = 'ssh -1 -o StrictHostKeyChecking=no -l root ' + payload

This almost certianly doesn't do what you want.  It runs the the first
command listed on the command line with all the other commands sent as
arguments.  Also, logging in remotely as root is often disabled.

< rest of code cut > 

> After a bit of further study, it would seem that threading is the way to go
> i.e. somehow getting the pid of the ssh command itself as send by BRUSH (the
> child pid ?), using some kind of Timer class based on the the "threading"
> module to see if the pid is still active, and if so, after some designated
> <time-out> period, killing the pid.

As far as I can tell, your ssh process doesn't hang, it's just waiting
for data, most likely a host key validation or a password, neither of
which you handle.

You didn't answer my original question either.  Why do you need to run
multiple commands on a remote server in Python?  If you just want a
simple command, 'ssh -l username host "command1; command2; command3"'
should do the trick.

-p




More information about the Python-list mailing list