[Twisted-Python] [Andrei.Doicin at cern.ch: timing out an ssh command]

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed May 7 10:31:40 EDT 2003

How is easy is it to script conch?  It'd be nice if it was the solution to
this guy's problem :)


----- Forwarded message excerpt from Andrei Doicin <Andrei.Doicin at cern.ch> -----

From: Andrei Doicin <Andrei.Doicin at cern.ch>
Newsgroups: comp.lang.python
Subject: timing out an ssh command
Organization: CERN
Xref: news.baymountain.com comp.lang.python:221802
To: python-list at python.org
Date: Wed, 7 May 2003 15:44:30 +0200

Dear fellow Pythonheads,

I have written a fairly nifty but "just beyond amateur" =) wrapper script in
python for sending ssh commands to remote hosts from the unix command line,
but would now like the ssh command to time out after a certain amount of
time (eventually to be specified as an option to the wrapper).

What would you advise is the best way to do this, out of the following
avenues to consider ?

- somehow making use of time.time or time.clock and/or select(x,x,x,timeout)
- sockets (i.e. making use of something like
http://www.timo-tasi.org/python/timeoutsocket.py by Timothy Malley)
- expect
- pexpect


A situation in which the ssh command hangs forever can be indicated as
follows, using the verbose option (whether necessary or not) of ssh to
illustrate what's going on at the fundamental level:

[client0-15:26:01] 130:adoicin/scripts> ssh -v target1 uptime
OpenSSH_3.4p1-CERN20020919, SSH protocols 1.5/2.0, OpenSSL 0x0090602f
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Rhosts Authentication disabled, originating port will not be
debug1: ssh_connect: needpriv 0
debug1: Connecting to target1 [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/adoicin/.ssh/identity type -1
debug1: identity file /home/adoicin/.ssh/id_rsa type -1
debug1: identity file /home/adoicin/.ssh/id_dsa type -1
... waits forever ...

the above example literally hangs forever unless you intervene with CTRL-C

----- snipped -----
----- End forwarded message excerpt -----

More information about the Twisted-Python mailing list