我需要提取"管理VLAN"从下面的输出中使用正则表达式并将值存储在变量中,以便稍后在我的脚本中使用。
set switch 100.10.100.100
set Username "test"
set Password "test"
spawn ssh -o StrictHostKeyChecking=no $Username@$switch
expect "*assword: "
send "$Password\r"
expect *>
send "enable\r"
expect "*#"
send "config\r"
expect "(config)#"
send "display something"
输出将是:
status : Connected
IP Address : 2.2.2.2
Mask : 255.255.255.255
Gateway : 2.2.2.1
Manage VLAN : 456
Manage priority : 0
Option60 : No
Switch : Enable
我怎么能实现这个目标?
答案 0 :(得分:1)
参见示例:
expect1.1> spawn bash -c "echo vlan : 1234"
spawn bash -c echo vlan : 1234
22902
expect1.2> expect -re {vlan *: *([0-9]+)}
vlan : 1234
expect1.4> set vlanid $expect_out(1,string)
1234
expect1.5> puts $vlanid
1234
expect1.6>