Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Pexpect not catching embeded ssh response
Hi everybody,
I was used to Bash + TCL + Expect but I migrated to Python + Pexpect and I'm encountering a little problem. I'm running python 3.6 with pexpect 4 in an ubuntu minimal vm. I'm spawning a child process to a proxy ssh machine and then trying to ssh again other hosts (this is in the aim of testing accesibility + accounts configurated after some network changes we hve to do). Problem is that pexpect library won't catch the second password prompt. I can login to the proxy ssh server but I can't "jump" to other machines. This is my script:

from __future__ import unicode_literals
import pexpect
import getpass

#username = input('Please enter your username:')
username = 'XXX'
password = getpass.getpass('Please enter your Password:')
username_AAA = input('Please enter your AAA username:')
password_AAA = getpass.getpass('Please enter your AAA Password:')

print('connecting to XXX')
log_file = open('log_aaa.txt', 'wb')
child = pexpect.spawn('ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' + username + '@XX.XXX.XX.XX', timeout=60)
child.logfile_read = log_file
print('Pinging AAA1 and AAA2 \n\n')
child.sendline('ping XX.XX.XX.XX -c 10')
child.sendline('ping XX.X.X.X -c 10')
print('Connecting to AAA1 and AAA2 to test connectivity \n\n')
child.sendline('ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' + username_AAA + '@X.X.X.X')
except pexpect.TIMEOUT:
    raise OurException("Did not catch the pattern")
# Script goes on a little bit to parse logs but it does not matter
I've done the same process of jumping from the proxy to other servers manually and of course it works. Password prompt received from other servers in proxy ssh server is like this:
Warning: Permanently added 'X.X.X.X' (RSA) to the list of known hosts. BLA-BLA-BLA@X.X.X.X's password:
But "password:" does not get matched Sad Well I'm not very experienced in Python nor Pexpect so I'm looking for some help, guidance... If someone can give a clue I would really appreciate it.
Thanks for your time Smile .

Well I changed the following line:
child.logfile_read = log_file
child.logfile = log_file
So I get everything the script does. It seems it catches the pattern and sends the commands, passwords and all that. Thing is that spawn child process does not catch the output of the second ssh session (embedded one) and as a consequence nothing is written on the log file.
So I change my question: Does anyone know how to make th spawn child process to catch the output from and embedded ssh session? Smile Smile
Haha thanks in advance for your time.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Collecting Output from Pexpect gw1500se 2 119 Jun-28-2019, 11:59 AM
Last Post: gw1500se
  Dialup Modem using pyserial - Need it to show response from the other end. Rython 1 243 Jun-20-2019, 10:09 PM
Last Post: roy
  Extra Argument In Help Response z3driver 3 137 Jun-19-2019, 07:34 PM
Last Post: z3driver
  Parsing Soap XML response grootkarzijn 7 297 Jun-14-2019, 01:30 AM
Last Post: snippsat
  Pexpect baby steps slouw 9 292 May-23-2019, 10:21 AM
Last Post: heiner55
  Pexpect module first step slouw 1 117 May-21-2019, 12:19 PM
Last Post: buran
  Catching Errors Alienspecimen 1 135 May-18-2019, 11:07 PM
Last Post: Larz60+
  Issues parsing the response from a request garnold 3 233 May-14-2019, 12:39 PM
Last Post: snippsat
  HTTP response capturing issue miunika 1 175 Mar-16-2019, 01:46 PM
Last Post: Larz60+
  HTTP response capturing issue anna 2 216 Mar-15-2019, 03:08 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)