Nathan,

You can also wrap your exec_command() in a method that does some
exception handling and reestablishes a connection if necessary.
Here's an example, http://dpaste.com/107690/  ... nasty but does the
trick.

--
Milan

On Thu, Oct 15, 2009 at 9:59 AM, Nathan Farrar <[email protected]> wrote:
>
> Is there any chance that your coworker has posted that code on the
> internet, somewhere?  :)
>
> On Wed, Oct 14, 2009 at 5:01 PM, Devin Cook <[email protected]> wrote:
> > Hi Nathan,
> >
> > Unfortunately this is a long standing issue... It has to do with Cisco's 
> > SSH implementation.
> >
> > http://www.lag.net/pipermail/paramiko/2008-June/000728.html
> >
> > I believe one of my coworkers has whipped up an expect-like wrapper using 
> > the lower level API. I think he invokes a shell and then uses .send() and 
> > .recv() on it.
> >
> > -Devin
> > ________________________________________
> > From: [email protected] [[email protected]] On Behalf Of 
> > Daniel Swarbrick [[email protected]]
> > Sent: Wednesday, October 14, 2009 4:38 PM
> > To: Nathan Farrar
> > Cc: [email protected]
> > Subject: Re: [paramiko] Executing multiple commands within a single 
> > connection
> >
> > On Wed, 2009-10-14 at 12:53 -0600, Nathan Farrar wrote:
> >> I'm using paramiko to manage cisco devices remotely.  It works
> >> beautifully when I have a script open a connection to a device,
> >> execute a command, then close the connection.  However, if I connect
> >> and then attempt to execute a command, and then a second command, an
> >> error is thrown.
> >>
> >> If I comment out the second client.exec_command() line, there are no
> >> problems.  Any tips to get this to work correctly?
> >>
> >
> > It's not a Paramiko issue... I discovered the same thing a while back,
> > when talking to Cisco devices. It appears that their SSH implementation
> > closes the whole connection after the first command, instead of just
> > closing that one channel.
> >
> > Unless you approach it quite differently (use a pty), your only real
> > option is to reconnect for each command you want to execute.
> >
> >
> > _______________________________________________
> > paramiko mailing list
> > [email protected]
> > http://www.lag.net/cgi-bin/mailman/listinfo/paramiko
> >
>
>
>
> --
> "The presence of those seeking the truth is infinitely to be preferred
> to the presence of those who think they've found it."
>
> –Terry Pratchett
>
> _______________________________________________
> paramiko mailing list
> [email protected]
> http://www.lag.net/cgi-bin/mailman/listinfo/paramiko

_______________________________________________
paramiko mailing list
[email protected]
http://www.lag.net/cgi-bin/mailman/listinfo/paramiko

Reply via email to