1

我正在编写一个脚本来自动化IOS Cisco路由器上的指令,使用expect命令。

这是我写的脚本:

#!/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在脚本末尾添加一个命令,那么所有这些都可以正常工作。用户正确进入界面配置模式,时钟频率更新良好。但事实是,我不希望用户进行交互。

所以我真的不明白发生了什么以及为什么我不能就这样结束脚本......

如果你有任何线索......?

4

1 回答 1

1

I finally managed to solve my issue by myself.

It's a bit cheaty but... well it works.

Given that it's the last expect command which does not work, I've added a last "useless expect" at the end of my script :

expect "*(config)" {
        send "interface Serial0/0/0 \r"
}
expect "*(config-if)" {
        send "clock rate 14400\r"
}
expect "*(config-if)" {
        send "end"
        close
}

Anyway, if someone has a proper way to do it, I'm still open

于 2016-05-31T15:48:59.167 回答