问题
I want to automate the following scenario:
- Login into a router
- Give reload
- When reloading a router, press ESP key continuously.
- When pressing a ESP key , boot> prompt will come. execute some commands in this.
I can do the above things manually, using "Teraterm" and console. But how to do this inside a TCL script.
Please help me to do this.
Thanks, Balu P.
回答1:
You first need to find an interactive console program that you can issue the commands from. You may find that plink.exe
from the PuTTY suite is suitable. The system telnet.exe
is not suitable, as it has a special flag set on it that prevents automation, and TeraTerm isn't suitable because it is a GUI program as far as I can see (GUI program automation is very difficult to say the least, and you probably don't want to do it if there's any easier way).
Once you can do the task interactively, plug it inside of an expect script. It's fairly straight forward.
- Start with
spawn
, making the program run and passing in the arguments required to connect to the other system. - Interact with the remote system.
- Listen for a suitable prompt with
expect
. (Remember, this might include prompts to send a username and password!) - Tell it what to do with
send
. Remember that\r
is how you send a Return.
- Listen for a suitable prompt with
- When you're done,
close
.
Of course, things get more complex when you're also dealing with conditionals, error conditions and timeouts; expect
can handle those, but the code is a bit more complex. Ask another question once you've got a concrete problem we can help you with.
回答2:
I have use console server to automate this. Its working fine
来源:https://stackoverflow.com/questions/24270152/how-to-automate-console-scenario-using-tcl-script