#21 Pxssh fails to find prompt in busybox (ash) shell

open
nobody
None
5
2014-08-19
2008-10-17
Urz
No

Initially, I got this:

christian@Piro:~/internet_counter$ python internet_counter.py
root@10.1.1.1's password: xxxxxx

BusyBox v0.61.pre (2007.08.13-12:46+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# PS1='[PEXPECT]\$ '
PS1='[PEXPECT]\$ '
[PEXPECT]\$ set prompt='[PEXPECT]\$ '
set prompt='[PEXPECT]\$ '
[PEXPECT]\$ Login Failed <pxssh.pxssh object at 0xb7d992ec>
version: 2.1 ($Revision: 395 $)
command: /usr/bin/ssh
args: ['/usr/bin/ssh', '-l', 'root', '10.1.1.1']
patterns:
<class 'pexpect.TIMEOUT'>
\[PEXPECT\][\$\#]
buffer (last 100 chars):
before (last 100 chars): set prompt='[PEXPECT]\$ '
[PEXPECT]\$
after: <class 'pexpect.TIMEOUT'>
match: <class 'pexpect.TIMEOUT'>
match_index: 0
exitstatus: 255
flag_eof: False
pid: 28987
child_fd: -1
closed: True
timeout: 10
delimiter: <class 'pexpect.EOF'>
logfile: <open file '<stdout>', mode 'w' at 0xb7dac068>
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.1
delayafterclose: 0.1
delayafterterminate: 0.1

Upon closer examination it looked like it was having trouble finding the prompt. I added some code to pxssh and got this:

christian@Piro:~/internet_counter$ python internet_counter.py
root@10.1.1.1's password: xxxxxx

BusyBox v0.61.pre (2007.08.13-12:46+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# PS1='[PEXPECT]\$ '
PS1='[PEXPECT]\$ '
[PEXPECT]\$ set prompt='[PEXPECT]\$ '
set prompt='[PEXPECT]\$ '
[PEXPECT]\$ PS1="[PEXPECT]\$ "
PS1="[PEXPECT]\$ "
[PEXPECT]$ uptime
uptime
uptime: No such file or directory
[PEXPECT]$ uptime
uptime: No such file or directory

exit
exitConnection to 10.1.1.1 closed.

Note this is with self.logfile = sys.stdout plus my script printing things, so the above transcriptions may have parts doubled up. Below is a patch with the modifications I made. Sorry if the web form breaks it.

*** backup-pxssh.py 2008-10-17 20:18:39.000000000 +1000
--- pxssh.py 2008-10-17 20:47:37.000000000 +1000
***************
*** 36,41 ****
--- 36,42 ----
# used to set shell command-line prompt to something more unique.
self.PROMPT_SET_SH = "PS1='[PEXPECT]\$ '"
self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\$ '"
+ self.PROMPT_SET_ASH = "PS1=\"[PEXPECT]\$ \""

### TODO: This is getting messy and I'm pretty sure this isn't perfect.
### TODO: I need to draw a better flow chart for this.
***************
*** 130,135 ****
--- 131,139 ----
self.sendline (self.PROMPT_SET_CSH)
i = self.expect ([TIMEOUT, self.PROMPT], timeout=10)
if i == 0:
+ self.sendline (self.PROMPT_SET_ASH)
+ i = self.expect ([TIMEOUT, self.PROMPT], timeout=10)
+ if i == 0:
return 0
return 1

Discussion