[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

read_nonblocking error in pxssh

jrpfinch

1/16/2008 5:24:00 PM

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:

>>> import pxssh
>>> s=pxssh.pxssh()
>>> s.login("myhost","root","mypass")
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
root@myhost'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
root@myhost:/ #

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
4 Answers

Sean DiZazzo

1/16/2008 10:54:00 PM

0

Just glanced at the docs, but it might be worth a shot...

try:

> >>> import pxssh
> >>> s=pxssh.pxssh()
> >>> s.login("myhost","root","mypass", auto_prompt_reset=False)

Maybe???

Otherwise, I have used and modified this script with great success:

(ssh_session.py) http://www.koders.com/python/fidA430838E5789710E4DCF34C414AD75EB4EE...

Good luck.

~Sean

On Jan 16, 9:24 am, jrpfinch <jrpfi...@gmail.com> wrote:
> 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:
>
> >>> import pxssh
> >>> s=pxssh.pxssh()
> >>> s.login("myhost","root","mypass")
>
> 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
> root@myhost'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
> root@myhost:/ #
>
> 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

kayvansylvan

2/1/2008 6:49:00 PM

0

On Jan 16, 9:24 am, jrpfinch <jrpfi...@gmail.com> wrote:
> 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:
>
> >>> importpxssh
> >>> s=pxssh.pxssh()
> >>> s.login("myhost","root","mypass")
>
> 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
> root@myhost'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
> root@myhost:/ #
>
> 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

Jinno

2/2/2008 12:32:00 AM

0

On Feb 1, 10:49 am, kayvansyl...@gmail.com wrote:
> On Jan 16, 9:24 am, jrpfinch <jrpfi...@gmail.com> wrote:
>
>
>
> > 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:
>
> > >>> importpxssh
> > >>> s=pxssh.pxssh()
> > >>> s.login("myhost","root","mypass")
>
> > 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
> > root@myhost'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
> > root@myhost:/ #
>
> > 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

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

kayvansylvan

2/2/2008 7:10:00 AM

0

On Feb 1, 4:31 pm, Jinno <jeremiah.ji...@gmail.com> wrote:
> 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