0

pexpect を使用してデバイスに telnet し、続いてそのデバイスから別のデバイスに telnet して、2 番目のデバイスでコマンドの結果を出力しようとしていますが、できません。ここに私が書いたスクリプトと私が得ているエラーがあります

大変助かります。ありがとう

import pexpect

child = pexpect.spawn('telnet 192.168.2.45');

child.expect('assword:');
child.sendline('getin');

child.expect('AS-C5350-02>');
child.sendline('telnet 192.168.1.2'); 
child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n nPassword:');
child.sendline('cisco'); 
child.expect('ipipgw01>'); 
child.sendline('sh clock');
child.sendline('exit');

child.expect(pexpect.EOF);

print child.before;

ここに私が得続けるエラーがあります

Traceback (most recent call last):
  File "expect_telnetback.py", line 14, in <module>
  child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n    \nPassword:');
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
  return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
  return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
  raise TIMEOUT (str(e) + '\n' + str(self))
  pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
 <pexpect.spawn object at 0xb7752a2c>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/telnet
args: ['/usr/bin/telnet', '192.168.2.45']
searcher: searcher_re:
0: re.compile("
Trying 196.192.7.14 ... Open


User Access Verification

Password:")
buffer (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open


User Access Verification

Password: 
before (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open


User Access Verification

Password: 
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 26275
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
4

0 に答える 0