How to automate console scenario using TCL script? [closed]

邮差的信 提交于 2019-12-30 11:32:07

问题


I want to automate the following scenario:

  1. Login into a router
  2. Give reload
  3. When reloading a router, press ESP key continuously.
  4. 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.

  1. Start with spawn, making the program run and passing in the arguments required to connect to the other system.
  2. Interact with the remote system.
    1. Listen for a suitable prompt with expect. (Remember, this might include prompts to send a username and password!)
    2. Tell it what to do with send. Remember that \r is how you send a Return.
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!