我很难弄清楚如何用python/exscript编写正则表达式,以便在我运行"copy run tftp“时,提示与输出匹配……
例如,提示符更改为...
“远程主机的地址或名称[]?”
然后..。
“目标文件名lab-3560.confg?”
我知道我需要在执行命令conn.execute('copy run tftp')之前设置"set_prompt()“,但是没有关于正确语法的线索。
发布于 2016-08-20 01:50:45
有很多方法可以做到这一点,下面是一个例子:
因此,您所需要做的就是解析返回的提示符/文本,下面是此link的一个小示例
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)https://stackoverflow.com/questions/38984101
复制相似问题