#1
|
|||
|
|||
Scripting Errors
Hello,
I have been using the attached script successfully for a while now. I have recently run into a few issues. The first one that I've run into is that it seems like the script might be timing out while running certain commands that generate large amounts of output, one of the generates almost 26,000 lines of output from the one command. Is there something in the script that I am using that could be causing that or is there something I could add to keep it from causing errors? You can reference the attached .jpeg named "Scripting Error". The second issue that I have run into is, I have the script set up to read the hostname from the device it is connected to and append the hostname to the generated log file. This has been working beautifully until recently. There is a command that I need to run that changes the hostname of the device from "na-us-265-techcenter-cs01#" to "na-us-265-techcenter-cs01%guest-ion#". Two things happen at this point that I do not want to happen. The first is when it does decide to run the commands in the commands file that come after, the script will generate a new log file with the hostname as "na-us-265-techcenter-cs01%guest-ion#". I do not want it to do that; I would like for it ignore the "%guest-ion#" or "%265-shop1#" and keep using the same log file. The third issue is slightly related to the second issue. Sometimes when I get to the portion of my commands that changes the hostname with the added "%guest-ion#" or "%265-shop1#" on the hostname, the script will freeze up and not continue running the commands that I need it to run once the device is in the routing context. It does not spit out any errors with the script; it just stops running altogether. I have attached pictures of the errors, and the script I have been using. Any help would be greatly appreciated. Thanks, Ryan |
#2
|
|||
|
|||
Hi Ryan,
What version of SecureCRT are you using? Quote:
When you see the error, are you still connected to the device in SecureCRT? Quote:
Quote:
|
#3
|
|||
|
|||
I'm using SecureCRT Version 7.3.4 (x64 build 839).
Quote:
Quote:
Starting at line 195: Code:
' Send each command one-by-one to the remote system: For Each strCommand In vCommands crt.Screen.Send vbCRLF crt.Screen.WaitForString vbLF strHostname = crt.Screen.Readstring("#","(") strOrigPrompt = strPrompt strConfigPrompt = ")#" strPrivPrompt = "#" Code:
' Set the log file name based on the remote host's IP ' address and the command we're currently running. We also ' add a date/timestamp to help make each filename unique ' over time. strLogFile = Replace( _ g_strLogFileTemplate, _ "IPADDRESS", _ strHostname) Thanks, Ryan |
#4
|
|||
|
|||
Hi Ryan,
I noticed that the error dialog doesn't match the script you posted. Also, the line number in the error just doesn't line up with a line that should cause the type of error you are seeing. I would expect line 265 to be a ReadString(), WaitForString() or Send() call. Would you post the script that matches the error message you are seeing? Make sure that you remove any sensitive data prior to posting. |
#5
|
|||
|
|||
Quote:
|
#6
|
|||
|
|||
Hi Ryan,
Thanks for the update. What difference exists in the amount of time it takes to run the commands manually vs. the script? How high does your memory usage get when you run the script? How much of that is related to SecureCRT? |
#7
|
|||
|
|||
Quote:
While using the script it took it about nine minutes before it ran into an error. Probably about 50% done with the commands. The memory usage spiked at 32,000 K and CPU utilization spiked at 27%, |
#8
|
|||
|
|||
Hi Ryan,
Thanks for the information. When the example script was written, it was not anticipated that commands would generate such large amounts of data. I have been able to reproduce a similar issue when I run a command that generates lots of data. It seems like the connection is timing out since it is taking so long as a result of so much data being added to a variable which results in the script failure due to the lost connection. The solution would be to modify the script example to log lines of data as 1 or a few are received rather than capturing all of the output in a variable and then logging it. If I have time to rework the example, I will post here. |
#9
|
|||
|
|||
Hi Ryan,
I have attached a modified version of what you posted that may help with the issue you are seeing when trying to execute a command that can have a large amount of output. Does this help to resolve the issue? |
#10
|
|||
|
|||
So the modified script fixed the losing of connection error.
Now the issue I have is, sometimes when I get to the portion of my commands that changes the hostname with the added "%guest-ion#" or "%265-shop1#" on the hostname, the script will freeze up and not continue running the commands that I need it to run once the device is in the routing context. It does not spit out any errors with the script; it just stops running altogether. I have the script setup to capture the hostname, to append to the log file. However, when it gets to the routing context part it freezes. It doesn't produce any errors but won't continue with the commands. The hostname changes from "na-us-265-techcenter-cs01" to "na-us-265-techcenter-cs01%guest-ion#" or "na-us-265-techcenter-cs01%265-shop1#". |
#11
|
|||
|
|||
Hi Ryan,
There are probably a few ways you can handle the prompt change. My suggestion would be determine the prompt again if you send a command on line 214 that you know will change the prompt. You could use lines 180 through 194 again. You might even want to put that code into a function. so you are not repeating code again. |
#12
|
|||
|
|||
Quote:
Code:
' Send each command one-by-one to the remote system: For Each strCommand In vCommands crt.Screen.Send vbCRLF crt.Screen.WaitForString vbLF strHostname = crt.Screen.Readstring("#","(","%") strOrigPrompt = strPrompt strConfigPrompt = ")#" strPrivPrompt = "#" strRoutContx = "%" If strCommand = "conf t" Then strPrompt = strConfigPrompt If strCommand = "end" Then strPrompt = strPrivPrompt If strCommand = "exit" Then strPrompt = strConfigPrompt If strCommand = "routing-context vrf guest-ion" Then strPrompt = strRoutContx If strCommand = "" Then Exit For |
#13
|
|||
|
|||
Hi Ryan,
Perhaps I don't understand the situation, but it seems like you are already doing something similar to your goal. Rather than wait for "#" you could wait for "shop1#". Does this work for you? |
#14
|
|||
|
|||
Quote:
Now I'm running into another error. See attached screenshot. Last edited by jdev; 10-01-2015 at 10:09 AM. Reason: Removing sensitive username & password from attached script |
#15
|
||||
|
||||
The error you're seeing is occurring when the script is attempting to open the log file to write something, but the path specified isn't valid (or doesn't exist).
So, You'll want to do some debugging. Try to find out what the path is for the file the script trying open. Two quick ideas come to mind; both involve adding a single line of code right before line #290. Option 1: Use a MessageBox Somewhat disruptive, but you'll see the full path: MsgBox "Here's the log file: " & strLogFileOr... Option2: Use SecureCRT's status bar Less disruptive, but if the path is really long, you may not see all of it: g_objNewTab.Session.SetStatusText "Log: " & strLogFileOnce you can see what the path is, you'll find out if there's a folder or two that you need to create or modify the template variable in your script to reflect the correct/accurate folder, etc. --Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support Last edited by jdev; 10-01-2015 at 11:24 AM. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|