0

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. Login into a router
  2. Give reload
  3. Press Esp kep from keyboard continuously (You will get boot prompt by this)

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

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.

rcubefather
  • 1,534
  • 6
  • 25
  • 49

1 Answers1

1

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"

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.

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

ASCII Table

ASCII Non-Printable

Dinesh
  • 16,014
  • 23
  • 80
  • 122
  • Hi Dinesh... Thanks a lot for your answer. I am seeing the following issue when i run my script. As soon as i give reload, its shows "Connection to host lost", its not waiting for random boot text. Please guide me to overcome this issue. – rcubefather Jul 07 '14 at 11:04
  • Are you using the telnet connection with a console server or via management IP ? In case of console server, telnet connection will retain as such, but with the management IP, it will be lost since the device is going for reboot – Dinesh Jul 07 '14 at 15:41
  • I am using Management IP. Thanks for your help Dinesh. I will try this by using console server. – rcubefather Jul 07 '14 at 16:45
  • Thanks so much Dinesh... I have used console server and its working now. – rcubefather Jul 08 '14 at 16:11