Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-25-2015, 08:11 AM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
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
Attached Images
File Type: jpg Scripting Error.jpg (209.6 KB, 211 views)
File Type: jpg Scripting Error - Routing-Context - Guest Ion.jpg (66.9 KB, 210 views)
File Type: jpg Scripting Error - Routing-Context - 265-shop.jpg (61.9 KB, 179 views)
Attached Files
File Type: txt RDH-SC-LR-SSH2.vbs.txt (27.0 KB, 200 views)
Reply With Quote
  #2  
Old 09-25-2015, 09:13 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Ryan,

What version of SecureCRT are you using?
Quote:
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".
It looks like the connection is closing.

When you see the error, are you still connected to the device in SecureCRT?
Quote:
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.
This would require that you capture and use the old host name for the log file name.
Quote:
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.
Is the prompt changing when you change the host name?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 09-25-2015, 09:41 AM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
Quote:
Originally Posted by rtb View Post
What version of SecureCRT are you using?
I'm using SecureCRT Version 7.3.4 (x64 build 839).

Quote:
Originally Posted by rtb View Post
It looks like the connection is closing.
When you see the error, are you still connected to the device in SecureCRT?
The connection is getting closed. The reason I think it might have something to do with the script is because if I run all of the commands in the command chat window while connected to the device without the script they run fine without the connection closing. What I notice while running the script is that when it gets to the commands that generate a lot of output, it tends to freeze up. I don't know if this is caused because it's logging everything to the log file at the same time. I made sure that the default session that the script uses has NO-OP checked in the settings and is set for sixty seconds to keep the session from being closed.


Quote:
Originally Posted by rtb View Post
This would require that you capture and use the old host name for the log file name.
I have the script set up to capture the old host name, I believe.

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 = "#"
And at line 259:
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)
Quote:
Originally Posted by rtb View Post
Is the prompt changing when you change the host name?
Yes it goes from "na-us-265-techcenter-cs01#" to "na-us-265-techcenter-cs01%guest-ion#" or "na-us-265-techcenter-cs01%265-shop1#". Just to note that the "guest-ion#" won't change, but the "265-shop1#" will change depending on the device's site code that I'm connected to. For example, if I'm working on a site that has a site code that is 305, it would change to "305-shop1#".

Thanks,

Ryan
Reply With Quote
  #4  
Old 09-25-2015, 05:58 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 09-26-2015, 05:40 PM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
Quote:
Originally Posted by rtb View Post
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.
Sorry, about that. Attached is a new screenshot and the Script I'm using.
Attached Images
File Type: jpg Scripting Error.jpg (225.2 KB, 207 views)
Attached Files
File Type: txt RDH-SC-LR-SSH2-Error.vbs.txt (26.9 KB, 183 views)
Reply With Quote
  #6  
Old 09-28-2015, 03:17 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 09-29-2015, 04:20 AM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
Quote:
Originally Posted by rtb View Post
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?
Without using the script it takes around forty seconds to run the commands. The memory usage spiked around 60,000 K CPU utilization spiked around 30%.

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%,
Reply With Quote
  #8  
Old 09-29-2015, 10:58 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #9  
Old 09-29-2015, 03:24 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
Attached Files
File Type: txt RDH-SC-LR-SSH2-Error.vbs.txt (26.4 KB, 174 views)
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #10  
Old 09-30-2015, 12:25 AM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
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#".
Reply With Quote
  #11  
Old 09-30-2015, 12:08 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #12  
Old 09-30-2015, 01:24 PM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
Quote:
Originally Posted by rtb View Post
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.
Okay so I've added the following to the script:
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
The issue I have now, and am not sure how to fix is that the second routing-context vrf is "265-shop1" the problem with that is that that will not always be the same. It changes depending on the site code that I'm running the script on so if the site is "78" it would change to "78-shop1". Is there a way to make it to where it ignores up to the first four characters before "-shop1"? It could be anywhere from a number from 1 - 9999. Or is there a more elegant way of handling this?
Reply With Quote
  #13  
Old 09-30-2015, 06:08 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #14  
Old 09-30-2015, 08:29 PM
M1NDN1NJ4 M1NDN1NJ4 is offline
Registered User
 
Join Date: Nov 2013
Posts: 31
Quote:
Originally Posted by rtb View Post
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?
So I added what I think should work for the "shop1#" you can take a look and see at the attached script.

Now I'm running into another error. See attached screenshot.
Attached Images
File Type: jpg Error-Path not found.jpg (396.1 KB, 182 views)
Attached Files
File Type: txt RDH-SC-LR-SSH2-Error.vbs.txt (26.6 KB, 186 views)

Last edited by jdev; 10-01-2015 at 10:09 AM. Reason: Removing sensitive username & password from attached script
Reply With Quote
  #15  
Old 10-01-2015, 11:20 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 937
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: " & strLogFile
Or...
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: " & strLogFile
Once 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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 09:34 PM.