我正在寻找最后几天来解决我的问题,所以我终于来到这里。
我需要编写一个应该从Linux/Debian系统打开的Tcl脚本。问题是,脚本应该登录到Cisco路由器,然后进入特殊的tclsh模式,在那里它应该获得表示txload的SNMP值。过了一会儿,我得到了tclsh模式下的值(它支持SNMP),但是我无法将它返回到我的脚本中。它仍然只存在于路由器tclsh模式中。我的脚本应该根据我在tclsh中已经拥有的值来更改其他一些值,但是不再需要tclsh。
下面是我的问题:我如何从tclsh获得$ifnum值,但我仍然可以在脚本中使用一些循环,因为我需要在一些循环中使用$ifnum作为条件?
正如您所看到的,这个脚本还没有完成,但正如我说的,我被困在这里,试图弄清楚:
#!/usr/bin/expect -f
set gateway [lindex $argv 0]
set serial [lindex $argv 1]
set timeout 5
spawn telnet $gateway
expect "Password:"
send "cisco\r"
expect "*>"
send "en\r"
expect "Password:"
send "cisco\r"
expect "*#"
send "set ifnumstr \[snmp_getone odczyt 1.3.6.1.4.1.9.2.2.1.1.24.6\]\r"
expect "*}"
send "regexp \{val='(\[0-9\]*)'\} \$ifnumstr \{\} ifnum \r"
expect "*#"
send "puts \$ifnum \r"
expect "*#"发布于 2015-01-27 03:06:42
我会让它打印出在标记之间寻找的东西,然后在其RE匹配模式中使用expect来获取值。
send "puts \"if\\>\$ifnum<if\"\r"
expect -re {if>(.*?)<if}
# Save the value in a variable in the *local* script, not the remote one
set ifnum $expect_out(1,string)https://stackoverflow.com/questions/28158873
复制相似问题