Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python Exscript需要为cisco交换机的set_prompt()创建正则表达式_Python_Cisco_Exscript - Fatal编程技术网

使用Python Exscript需要为cisco交换机的set_prompt()创建正则表达式

使用Python Exscript需要为cisco交换机的set_prompt()创建正则表达式,python,cisco,exscript,Python,Cisco,Exscript,很难弄清楚如何在python/exscript中编写正则表达式,以便在运行“copy-run-tftp”时提示与输出匹配 例如,提示更改为 “远程主机[]的地址或名称?” 然后去 “目标文件名[lab-3560.confg]?” 我知道我需要在执行命令conn.execute('copy run tftp')之前设置“set_prompt()”,只是不知道正确的语法 因此,您只需解析返回的提示符/文本,下面是一个小示例: 有很多方法可以做到这一点,下面是一个例子: 因此,您只需解析返回的提示符/

很难弄清楚如何在python/exscript中编写正则表达式,以便在运行“copy-run-tftp”时提示与输出匹配

例如,提示更改为

“远程主机[]的地址或名称?”

然后去

“目标文件名[lab-3560.confg]?”


我知道我需要在执行命令conn.execute('copy run tftp')之前设置“set_prompt()”,只是不知道正确的语法

因此,您只需解析返回的提示符/文本,下面是一个小示例:


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

因此,您只需解析返回的提示符/文本,下面是一个小示例:

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)