1

Having a hard time figuring out how to write a regular expression in python/exscript so that the prompt matches the output when i run "copy run tftp"...

For example the prompt changes to...

"Address or name of remote host []?"

then to...

"Destination filename [lab-3560.confg]?"

I know I need to set the "set_prompt()" prior to executing the command conn.execute('copy run tftp') just no clue on the proper syntax(s)

4

1 回答 1

-1

有很多方法可以做到这一点,这里有一个例子:

所以你需要做的就是解析返回的提示/文本,这里有一个来自这个链接的小例子:

import pexpect

switch_ip = "10.0.0.1"
switch_un = "user"
switch_pw = "s3cr3t"
switch_port = "Gi2/0/2"
switch_vlan = 300
config = "lab-3560.confg"

child = pexpect.spawn('ssh %s@%s' % (switch_un, switch_ip))
child.logfile = sys.stdout
child.timeout = 4
child.expect('Address or name of remote host []?')
child.sendline(switch_ip)
child.expect('Destination filename [lab-3560.confg]?')
child.sendline(config)
于 2016-08-19T17:50:44.563 回答