[Twisted-Python] Conch SSH help?

Paul Swartz z3p at twistedmatrix.com
Fri Jun 17 13:43:38 EDT 2005


On Thu, 2005-06-16 at 15:25 -0700, Nick Arnett wrote:
> I'm getting stuck trying to do something I imagined would be easy in 
> Conch.  I want to log into a server, ls a directory, then grep inside a 
> certain file in each of the directories found by the ls command.
> 
> I've had no trouble logging in and running ls, then capturing its 
> output.  But then I'm stuck.  I can't figure out where to put the loop 
> through the directories.  I can see how to do one in a new channel, but 
> I sure can't see how to run the series of them and capture their 
> output.  I want to end up with a data structure that has the directory 
> name and the results of the grep as a list: [(dir, grep_results),...].

It sounds like you want something like DeferredList.

> I've tried calling my "grep" channel object repeatedly and that sort of 
> works, but only does the first seven or eight and fails.  I've tried 
> putting the loop in the channelOpen method of the "grep" channel and 
> that never gets any results.  I tried building a series of callbacks in 
> there and running it, but that doesn't work, either.

What fails?  Does the channel fail to open?  Does it return the wrong
results?

> What I also find confusing is that I run the command with sendRequest, 
> but the results come back in the dataReceived method -- how does it know 
> which command's results it is receiving?

sendRequest tells the server what command to run.  The server runs that
command, and connects stdout/stdin to the SSH connection.  dataReceived
is then called with the data from stdout.

If you can get the code even into one file, that would be helpful.  It's
hard to know quite what's going on without seeing what you're doing.

-p
-- 
       Paul Swartz
(o_    http://z3p.livejournal.com/  _o)
//\    z3p at twistedmatrix.com        /\\
V_/_   AIM: z3penguin              _\_V->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20050617/5c689b98/attachment.pgp 


More information about the Twisted-Python mailing list