Log into Cisco router, perform cmds and log to a file
I'm having difficulty in creating a script to log into a cisco router, prompted with username and password, perform commands and log to a file.
I saw an example. I'm able to log into the router with username and password. Is there an example I can use to refer to? Thanks for help (in advance) |
Hi stuartX,
Thanks for the question. We have examples as well as information explaining how the examples work in the scripting manual that we published to www.vandyke.com. You can find the downloadable PDF file at the following location: http://www.vandyke.com/support/tips/...ing/index.htmlChapter 3 discusses connecting to remote machines, chapters 4 and 5 discuss interacting with the remote machine (performing commands) and chapter 7 discusses logging data to files. Does this information help as you write your script? Did you have any specific questions about the example you found? If so, would you post them along with the example you are referencing? |
Yes, I have questions. I searched and found an example from this link:
http://forums.vandyke.com/showthread.php?p=14178 I copied the example and changed the path for the Devices.txt file and of course modified the text file contents (x.x.x.x;Telnet). When I run the script, I get pass username and password. But it stops and nothing else happens. |
Hi stuartX,
Thanks for the update. Would you post the script you are using in your tests in a code block? Would you also cancel the script (Script / Cancel) when it is doing nothing, and tell me on what line the script is stopped? |
How do I create a code block on this forum?
Is the beginning Code:
and after |
How do I create the code block? or should I just copy/paste?
|
Here is the code from the link modified
Code:
# $language = "VBScript" It stops at line #56. |
Hi stuartX,
Thanks for posting the code in a code block. Here is line 56: Code:
crt.Screen.Send "sh ver " + chr(124) + " i IOS" + chr(124) + "Sw" + chr(13) Is line 56 in your script editor the same as the line I pasted above? I think that you may have better luck using the examples in the scripting manual that I referenced rather than trying to repurpose this example to your needs. |
Yes, your line 56 is the same as mine.
After the script logs in successfully, it just sits there at the prompt. no other commands are issued. |
Hi stuartX,
I am not able to reproduce the issue you are seeing. It seems odd that when you cancel the script using Script / Cancel it displays line 56 in the dialog. I have never seen a script hang on a send line. I have seen scripts hang on wait lines. Would you post a screenshot of the dialog you see when cancelling the script? |
2 Attachment(s)
Below is what I see after I execute the script (Forum.jpg)
When I perform a cancel (Forum2.jpg) Like I mention after execution, the prompt just sits there. I can hit Enter and the router responds with the next prompt, so its not hung. |
Hi stuartX,
Thanks for the screenshots. Based on the screenshot, it appears as though the problem is a result of not waiting for the correct thing on line 55. It is important to note that when interacting with a remote device, you must wait for strings that exactly match what you expect to see on the remote. This is discussed in detail in Chapter 4 of the scripting manual. In your script, it looks like you might be connecting to a device using an IP address, and based on the way the code is written in this example, you are waiting for the IP address and a hash or the IP address and an angle bracket followed by (enable). In the screenshot, even though you redacted it, it seems like the prompt on the device has a device name followed by an angle bracket. If you change line 55 (and subsequent wait lines) to be something similar to the following, do you get farther along in the script? Code:
crt.Screen.WaitForString "THIS_IS_MY_DEVICE1>" |
I apologize for the delay.
I copied and pasted the router name prompt into line 55 and I get the same thing. could you guide me on the following? (To less complicate matters) -take out the prompt(dialog box requesting information) and include the username & password in the code. It seems like it stops after username & password entry. |
Hi stuartX,
To remove the functionality that prompts you for data, you can remove from line #92 to the end of the script. On line #28, you will need to define a username. On line #36, you will need to define a password. I would also recommend replacing all "+" symbols with "&" symbols. I must say, however, that I don't think that this will help resolve the issue. You may want to try adding a timeout to the wait lines. For example: Code:
crt.Screen.WaitForString "THIS_IS_MY_DEVICE1>", 1 Due to the sensitive nature of the data involved in this project, you may want to send the modified script and a screenshot to support@vandyke.com with a subject of Attn: Todd - Forum thread #10303. |
Yes, I'll try to modify a few things to make it simpler.
I'll post the results once I have sucess. thanks for your help. |
All times are GMT -6. The time now is 11:00 AM. |