<div class="gmail_quote">On Fri, Oct 16, 2009 at 1:45 PM, Nathan Farrar <span dir="ltr">&lt;<a href="mailto:nathan.farrar@gmail.com">nathan.farrar@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m trying to automate the collection of data to remote devices over<br>
ssh via pexpect.  I had originally attempted (with limited success) to<br>
use paramiko, however due to cisco&#39;s ssh implimentation I cannot send<br>
mulitple commands over the same connection, which is absolutely<br>
essential.  Therefore, I&#39;m now attempting to use pexpect, but am<br>
having trouble getting started.  I have a simple script, such as:<br>
<br>
session = pexpect.spawn(&#39;ssh user@host&#39;)<br>
session.expect([pexpect.TIMETOUT, &#39;password:&#39;])<br>
session.send(&#39;password&#39;)<br>
print session.read() # shouldn&#39;t this display the logon banner &amp; command prompt?<br>
session.close()<br>
<br>
This code results in no output &amp; a hanging window. What am I doing incorrect?<br>
<br>
Additionally, I will need to add conditional pexpect statements, such<br>
that when I execute a command I want to gather the output, however if<br>
&#39;--More--&#39; is encountered (and it this can happen multiple times), I<br>
want to send a newline character to the session and continue gathering<br>
the output.<br>
<br>
Thanks for the help!<br>
Nathan<br>
<br>
--<br>
&quot;The presence of those seeking the truth is infinitely to be preferred<br>
to the presence of those who think they&#39;ve found it.&quot;<br>
<br>
–Terry Pratchett<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br>when using pexpect for ssh you can run into some issues, I have used to script some elaborate green screen apps, but not without some unforeseen bugs <br><br>when connecting to a new machine, most ssh client will ask you verify the fingerprint<br>
<br>something like: <br><br>&gt; are you sure you want to continue (yes/no)?<br><br>also session.send &lt; doesn&#39;t send eol &quot;\n&quot; but sendline does<br><br>So this should fix your connection<br><br>###<br>session = pexpect.spawn(&#39;ssh user@host&#39;)<br>
i = session.expect([pexpect.TIMETOUT, &#39;password:&#39;, &quot;yes/no&quot;])<br>if i == 2:<br>    session.sendline(&quot;yes&quot;)<br>    session.expect([pexpect.TIMETOUT, &#39;password:&#39;])<br>if i == 1:<br>    session.sendline(&#39;password&#39;)<br>
    print session.read() # shouldn&#39;t this display the logon banner &amp; command prompt?<br>session.close()<br>###<br><br>the other your question,  pexpects sendline(&#39;&#39;), will just send a newline <br><br>not perfect but should work<br>
###<br>license = &quot;&quot;<br>while True:<br>    i = session.expect([&quot;--more--&quot;, &quot;yes/no&quot;])<br>    if i == 1:<br>       break<br>    license += session.before<br>    session.sendline(&#39;&#39;)<br>
###<br><br><br>Vince<br>    <br><br><br><br>