TCL/预期::如何自动执行路由器引导加载程序功能 [英] TCL/Expect:: How to automate the router boot loader function

查看:110
本文介绍了TCL/预期::如何自动执行路由器引导加载程序功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是我以前的问题"TCL/Expect ::如何自动启动路由器启动方案?"的继续.由于没有得到任何回应,因此我创建了一个新问题.

This Question is the continuation of My old question "TCL/Expect:: How to automate the router booting scenario?". Since I am not getting any response for that I am creating a new question.

我的要求:我想自动执行路由器启动提示方案.这涉及以下步骤:

My requirement : I want to automate router boot prompt scenario. That involves following steps:

  1. 登录到路由器
  2. 重新加载
  3. 连续从键盘上按Esp kep(您将由此获得启动提示)

有什么方法可以自动执行此过程(重新加载...到...启动提示)

Is there any way to automate this inbetween process (reload... to ... boot prompt)

我尝试使用Donal在上一个问题中建议的"plink.exe".但是当路由器重新加载时,plink也会出现.

I tried to use "plink.exe" as suggested by donal in my previous question. But when router reloads plink is also coming out.

请建议我使用任何工具来自动化此操作.

Please suggest me any tool to automate this.

推荐答案

您可以使用sendexpect通过下面给出的代码进行此操作.

You can use send and expect to do this with code given below.

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键,我相信您会更愿意等待随机的文本出现在路由器的重新启动日志中.

After giving reload command, to get to the router's boot prompt, you are pressing the Esc Key and I believe you will prefer to wait for some random text which will appear on the reboot logs of router.

必须在代码段中添加该文本

That text has to be added in the code segment

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"}
        }

请确保您将此处的理想字符串"替换为您喜欢的文本.

Make sure, you are replacing the "your ideal string here" with your preferable text.

对于可打印和不可打印字符的ASCII字符,您可以参考以下链接.

You can refer the following links for the ASCII characters of printable and non-printable characters.

ASCII表

ASCII不可打印

这篇关于TCL/预期::如何自动执行路由器引导加载程序功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆