[Twisted-Python] How to tell when SSH command has finished in Conch?
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Wed Jan 9 11:46:25 MST 2013
On 06:19 pm, rodrigc at crodrigues.org wrote:
>Hi,
>
>I have a very similar question to the one that Vye Wilson
>recently asked, "Subject: What is The Correct Way to Close a Twisted
>Conch
>SSH Connection?"
>
>I am using Twisted Conch to write a program that
>ssh's into multiple machines and executes a single command.
>
>I am basically trying to do the equivalent of:
>
>for host in host1 host2 host3
>do
> ssh user at host "cat /etc/hosts"
>done
>
>
>To start things off, I took
>http://twistedmatrix.com/documents/current/conch/examples/sshsimpleclient.py
>and started modifying it. Here is the code which I have:
>
>http://pastebin.com/RXhjUcrS
>
>The problem is, I can't figure out how to tell when a command has
>completed, so that I can call reactor.stop().
>
>Not in the code example I posted above, I tried to use a DeferredList
>by
>following the example code in this blog
>post:
>
>http://technicae.cogitat.io/2008/06/async-batching-with-twisted-
>walkthrough.html
>
>but I ran into the same problem where I couldn't figure out how
>to tell when my command over SSH had terminated.
>
>As a kluge, I called reactor.callLater() with a timeout of
>20 seconds, and then called reactor.stop().
>
>Any ideas as to what I am doing wrong?
>Where in the Conch framework can I tell when a command
>over SSH has finished?
You can't tell when a command has finished. Commands are run in the
context of a channel. You can tell when a channel has closed because
its `closed` method is called.
You might find this spike of an SSH command endpoint interesting:
http://twistedmatrix.com/~exarkun/sshendpoint.py
Also note this is something that I would like to be better supported in
Conch:
http://twistedmatrix.com/trac/ticket/4698
Jean-Paul
More information about the Twisted-Python
mailing list