read_nonblocking error in pxssh


J

jrpfinch

I'm attempting to use the pxssh to execute commands on a remote
machine and do stuff with the output. Both machines are running SSH
Version Sun_SSH_1.0, protocol versions 1.5/2.0 and Intel Solaris 9.

I am hitting a problem with read_nonblocking in the pexpect module as
follows:
Trying command: ssh -q -l root gerard
Expect returned i=2
Expect returned i=1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pxssh.py", line 244, in login
if not self.synch_original_prompt():
File "pxssh.py", line 134, in synch_original_prompt
self.read_nonblocking(size=10000,timeout=10) # GAS: Clear out the
cache before getting the prompt
File "/opt/python2.5.1/lib/python2.5/site-packages/pexpect.py", line
824, in read_nonblocking
raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().

Running the ssh command from the shell yields:

bash-2.05# ssh -q -l root myhost
[email protected]'s password:
Last login: Wed Jan 16 17:10:32 2008 from x.x.x.x
Sun Microsystems Inc. SunOS 5.9 Generic January 2003
Sun Microsystems Inc. SunOS 5.9 Generic January 2003
[email protected]:/ #

I would be grateful if anyone could make a suggestion as to where I go
next? Is read_nonblocking(), the correct method to be using here?
Are there any options in pxssh I need to explore (I've tried ssh -t,
but this means the password entry fails with raise ExceptionPxssh
('password refused')).

Many thanks

Jon
 
Ad

Advertisements

K

kayvansylvan

I'm attempting to use thepxsshto execute commands on a remote
machine and do stuff with the output. Both machines are running SSH
Version Sun_SSH_1.0, protocol versions 1.5/2.0 and Intel Solaris 9.

I am hitting a problem with read_nonblocking in the pexpect module as
follows:


Trying command: ssh -q -l root gerard
Expect returned i=2
Expect returned i=1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pxssh.py", line 244, in login
if not self.synch_original_prompt():
File "pxssh.py", line 134, in synch_original_prompt
self.read_nonblocking(size=10000,timeout=10) # GAS: Clear out the
cache before getting the prompt
File "/opt/python2.5.1/lib/python2.5/site-packages/pexpect.py", line
824, in read_nonblocking
raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().

Running the ssh command from the shell yields:

bash-2.05# ssh -q -l root myhost
[email protected]'s password:
Last login: Wed Jan 16 17:10:32 2008 from x.x.x.x
Sun Microsystems Inc. SunOS 5.9 Generic January 2003
Sun Microsystems Inc. SunOS 5.9 Generic January 2003
[email protected]:/ #

I would be grateful if anyone could make a suggestion as to where I go
next? Is read_nonblocking(), the correct method to be using here?
Are there any options inpxsshI need to explore (I've tried ssh -t,
but this means the password entry fails with raise ExceptionPxssh
('password refused')).

Many thanks

Jon

Did you get anywhere with this? I have the exact same problem on a
CentOS Linux system.

---Kayvan
 
Joined
Feb 2, 2008
Messages
1
Reaction score
0
I don't know if anyone ever got back to you with a fix, but for me the fix was really simple.

I just added a self.sendline() and a time.sleep(0.5) right before the first read_nonblocking() call within synch_original_prompt

The reason is that you have to have stuff in the buffer in order to read it. In the case that they programmed for originally, **something** exists in their prompt (probably a space) after the $ or #. In my case (and probably yours) the last thing on the prompt **is** the $ or #, causing the buffer to be non-existent when the first read_nonblocking() happens. So all we do is put something there before the read.

Why not just get rid of the first read since it is just "clearing the buffer" anyway? Because then, although it would now work for us, it would no longer work for the original programmers.
 
J

Jinno

Did you get anywhere with this? I have the exact same problem on a
CentOS Linux system.

---Kayvan

I don't know if anyone ever got back to you with a fix, but for me the
fix was really simple.

I just added a self.sendline() and a time.sleep(0.5) right before the
first read_nonblocking() call within synch_original_prompt

The reason is that you have to have stuff in the buffer in order to
read it. In the case that they programmed for originally,
**something** exists in their prompt (probably a space) after the $ or
#. In my case (and probably yours) the last thing on the prompt
**is** the $ or #, causing the buffer to be non-existent when the
first read_nonblocking() happens. So all we do is put something there
before the read.

Why not just get rid of the first read since it is just "clearing the
buffer" anyway? Because then, although it would now work for us, it
would no longer work for the original programmers.

- Jinno
 
Ad

Advertisements

K

kayvansylvan

I don't know if anyone ever got back to you with a fix, but for me the
fix was really simple.

I just added a self.sendline() and a time.sleep(0.5) right before the
first read_nonblocking() call within synch_original_prompt

Thank you!!! That was exactly the right solution, and thank you very
much for the great explanation too.

---Kayvan
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top