TCL/Expect::如何自动化路由器引导加载程序功能
这个问题是我的老问题“TCL/Expect::如何自动化路由器引导场景?”的继续。因为我没有得到任何回应,所以我提出了一个新问题 我的要求:我想自动化路由器引导提示场景。这包括以下步骤:TCL/Expect::如何自动化路由器引导加载程序功能,tcl,expect,Tcl,Expect,这个问题是我的老问题“TCL/Expect::如何自动化路由器引导场景?”的继续。因为我没有得到任何回应,所以我提出了一个新问题 我的要求:我想自动化路由器引导提示场景。这包括以下步骤: 登录路由器 装填 连续按键盘上的Esp kep(您将得到引导提示) 是否有任何方法可以自动执行此中间过程(重新加载…到…引导提示) 我尝试使用donal在上一个问题中建议的“plink.exe”。但当路由器重新加载时,plink也会出现 请向我推荐任何自动执行此操作的工具。您可以使用send和expect对下面
请向我推荐任何自动执行此操作的工具。您可以使用
send
和expect
对下面给出的代码执行此操作
set username "admin"
set password "lab"
set router_ip 10.189.11.27
spawn telnet $router_ip
puts "Telnet to router device"
expect "Login"
send "$username\r"
expect "Password"
send "$password\r"
#Assuming the router will come up a prompt as 'Router>'
#and I am expecting for character '>'
expect ">"
send "enable\r"
expect "#"
#Sending reload command here
send "reload\r"
#Assuming it will prompt the user for confirmation.
#If your router won't prompt before reload, you can remove this
expect "confirm"
#Sending 'Enter' key to confirm
send "\r"
#Waiting for the portion of text to come when we have to give
#Esc key from keyboard
expect {
#Appearance of some text after which you prefer send Esc key
"your ideal string here" {puts "Going to send Esc key now"}
timeout {puts "I am still waiting to press the Esc key"}
}
#I hope by saying escape key you meant the 'Esc' key.
#In some routers, to get boot prompt, you have to press 'Ctrl+C'
#This will send 'Escape' key from keyboard.
send "\x1b\r"
#Assuming your boot prompt is 'boot>'
expect "boot>"
#Whatever configuration you want to change here, do it
#This will send 'Ctrl+]' to close the telnet connection gracefully
send "\x1d"
expect "telnet>"
send "quit\r"
expect "Connection"
在发出reload命令后,要进入路由器的引导提示符,您需要按Esc键,我相信您更愿意等待一些随机文本出现在路由器的重启日志上
该文本必须添加到代码段中
expect {
#Appearance of some text after which you prefer send Esc key
"your ideal string here" {puts "Going to send Esc key now"}
timeout {puts "I am still waiting to press the Esc key"}
}
请确保您正在用首选文本替换“此处的理想字符串”
可打印字符和不可打印字符的ASCII字符可参考以下链接
你好,迪内什。。。非常感谢你的回答。当我运行脚本时,我看到以下问题。只要我重新加载,它就会显示“主机连接丢失”,而不是等待随机启动文本。请指导我解决此问题。您是使用与控制台服务器的telnet连接还是通过管理IP?对于控制台服务器,telnet连接将保持不变,但使用管理IP时,它将丢失,因为设备将使用管理IP重新启动am。谢谢你的帮助,迪内什。我将尝试使用控制台服务器。非常感谢Dinesh。。。我现在已经使用了console服务器及其工作模式。