0

I am trying to use pexpect to dump long ACLs to Cisco IOS router, the ACL contents are in a string, which has about 100 lines of ACL entries, I used the following code:

for aclstr_line in aclstr.split('\n\r'):
   ssh_session.sendline('%s' % aclstr_line)
   ssh_session.expect('[(.+)#]')

ssh_session.interact()

ssh_session.sendline('interface vlan100')
ssh_session.expect('[(.+)#]')
ssh_session.sendline('ip access-group Inbound_ACL in')
ssh_session.expect('[(.+)#]')

The above first 5 lines of code works perfectly until ssh_session.interact(), but if I take off "ssh_session.interact()", the code breaks, logfile shows that the code does not complete configuring all ACL entries before proceeding to execute rest sendline commands, all sendline commands seem to be mixed with each other.

What could be the cause? thanks,

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
  • Is there a prompt or something you can expect when it's ready for the next command? `[(.+)#]` is very broad. Or did you mean to escape some of those characters, e.g. `\[(.+)#\]`? – Thomas K Nov 16 '13 at 02:00
  • Thanks, I doubt the problem is prompt related, I tried different prompt matching, what I am looking for is "#", which is Cisco IOS prompt in privileged mode. – user2998206 Nov 16 '13 at 22:22
  • Another possibility: the line terminator on which you're splitting could be wrong - try using the `splitlines()` method. – Thomas K Nov 18 '13 at 03:20

0 Answers0