display cur
(可写多行命令实现一次登录采集完成)#### 命令示例1:`0_]^interface loopback 0` #### 命令示例2:`1_]^interface loopback 0` #### 命令示例3:`]^interface loopback 0`
^
之前为回显匹配模式和回显完成标识符, 符号^
之后为实际下发的命令。0
和 1
表示, 0
代表精确匹配,回显的最后字符必须要一致;1
表示模糊匹配,回显标识符只需要在回显内容中出现即可,不需要回显标识符必须在回显的最后位置。执行完成最后
显示的最后一个字符,各厂商一般如下:厂商 | 回显标识符 |
---|---|
H3C | > |
HW | > |
ruijie | # |
cisco | # |
<H3C-TEST-01>system-view System View: return to User View with Ctrl+Z. [H3C-TEST-01]
例如此命令执行完成后回显标识符为]
而并非>
命令按照实际要下发的命令敲即可
用来匹配可能会出现但不一定出现的情况,如从ftp下载文件时如文件不存在的情况下正常下载是没问题的,但当本地已经存在此文件时就会提示输入[Y/N]让用户判断,在此情况下可以使用该语法。
示例 ftp> get G1 G1 already exists. Overwrite it? [Y/N]:Y 227 Entering Passive Mode (10,168,1,123,21,108) 150 Connection accepted. . 226 Transfer complete. 3698 bytes received in 0.199 seconds (18.17 Kbytes/s) ftp>
从双减号‘–’开始为python的字典格式,对应两个键值,建固定不可修改,值可修改。
键 | 值含义 | 举例 |
---|---|---|
incloude | 回显可能包含的字符串 | 如上代码所示在回显中包含[Y/N]: |
input | 匹配到可能包含的字符串后执行下发的字符串 | 包含[Y/N]: 的情况下输入Y |
示例1:配置接口ip 操作命令: 1_]^system-view 1_]^interface loopback 0 1_]^ip address 172.16.1.1 255.255.255.255 1_>^return 1_>^save fo 回显内容: system-view System View: return to User View with Ctrl+Z. [H3C-TEST-01]interface loopback 0 [H3C-TEST-01-LoopBack0]ip address 172.16.1.1 255.255.255.255 [H3C-TEST-01-LoopBack0]return <H3C-TEST-01>save fo Validating file. Please wait... Configuration is saved to device successfully. <H3C-TEST-01>
示例2:从ftp下载文件到网络设备 操作命令: 0_> ^ftp 10.168.1.123--{'incloude':'(none)):;Password:','input':'admin;admin'} 0_> ^cd . 0_> ^get G1--{'incloude':'[Y/N]:','input':'Y'} 回显内容 ftp 10.168.1.123 Press CTRL+C to abort. Connected to 10.168.1.123 (10.168.1.123). 220 Browser Ftp Server. User (10.168.1.123:(none)): admin 331 Password required for this user. Password: 230 User Logged In. Remote system type is UNIX. Using binary mode to transfer files. ftp> cd . 250 CWD command successful. ftp> get G1 G1 already exists. Overwrite it? [Y/N]:Y 227 Entering Passive Mode (10,168,1,123,21,108) 150 Connection accepted. . 226 Transfer complete. 3698 bytes received in 0.199 seconds (18.17 Kbytes/s) ftp>