最后期望的指令没有执行
Last expect instruction is not executed
我正在编写脚本,使用 expect 命令在 IOS Cisco 路由器上自动执行指令。
这是我写的脚本:
#!/bin/expect
#log_user 0
set timeout 60
set mode [lindex $argv 0]
spawn ssh myuser@10.0.0.254
expect "*assword:" {
send "mypassword\r"
}
expect "*>" {
send "enable \r"
}
expect "*#" {
send "conf t \r"
}
expect "*(config)" {
send "interface Serial0/0/0 \r"
send "clock rate 14400\r"
}
我的问题是,此脚本在 "router1(config)#" 状态停止。
但是如果我在我的脚本末尾放置一个 interact
命令,所有这些都可以正常工作。用户正确进入接口配置模式,时钟速率更新良好。
但事实是,我不希望用户进行交互。
所以我真的不明白发生了什么,为什么我不能就这样结束脚本...
如果你有任何线索......?
我终于自己解决了我的问题。
这有点作弊,但是...很好用。
鉴于这是最后一个 expect
命令不起作用,我在脚本末尾添加了最后一个 "useless expect" :
expect "*(config)" {
send "interface Serial0/0/0 \r"
}
expect "*(config-if)" {
send "clock rate 14400\r"
}
expect "*(config-if)" {
send "end"
close
}
不管怎样,如果有人有合适的方法,我仍然开放
我正在编写脚本,使用 expect 命令在 IOS Cisco 路由器上自动执行指令。
这是我写的脚本:
#!/bin/expect
#log_user 0
set timeout 60
set mode [lindex $argv 0]
spawn ssh myuser@10.0.0.254
expect "*assword:" {
send "mypassword\r"
}
expect "*>" {
send "enable \r"
}
expect "*#" {
send "conf t \r"
}
expect "*(config)" {
send "interface Serial0/0/0 \r"
send "clock rate 14400\r"
}
我的问题是,此脚本在 "router1(config)#" 状态停止。
但是如果我在我的脚本末尾放置一个 interact
命令,所有这些都可以正常工作。用户正确进入接口配置模式,时钟速率更新良好。
但事实是,我不希望用户进行交互。
所以我真的不明白发生了什么,为什么我不能就这样结束脚本...
如果你有任何线索......?
我终于自己解决了我的问题。
这有点作弊,但是...很好用。
鉴于这是最后一个 expect
命令不起作用,我在脚本末尾添加了最后一个 "useless expect" :
expect "*(config)" {
send "interface Serial0/0/0 \r"
}
expect "*(config-if)" {
send "clock rate 14400\r"
}
expect "*(config-if)" {
send "end"
close
}
不管怎样,如果有人有合适的方法,我仍然开放