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-21-2016, 03:55 PM
David0 David0 is offline
Registered User
 
Join Date: Sep 2016
Posts: 5
ReadingAndWriting Script Not Capturing All Output

Hello,

I am tinkering around with the excel ReadingAndWriting script to see what it can do and to modify it to fit my needs... and I'm having an issue with the script capturing ALL the output of the command.

I primarily work with Cisco switches and routers and I added the "show run int Gi1/0/10" command, for example, to the script. The script only picks up a certain amount of the output and never finishes writing to the excel book, in any config. Here is what the script picked up:

Code:
show run int Gi1/0/10
Load for five secs: 43%/4%; one minute: 44%; five minutes: 42%
Time source is NTP, 13:46:28.655 PDT Wed Sep 21 2016
Building configuration...
Current configuration : 556 bytes
!
interface GigabitEthernet1/0/10
 description SecureCRT VanDyke Example
 switchport access vlan 2
 switchport mode access
 switchport port-security maximum 2
 switchport port-security
 switchport port-security aging time 2
 switchport port-security violation protect
 switchport port-security aging type inactivity
 load-interval 30
 power inline never
 speed 100
 srr-queue bandwidth limit 12
 no snmp trap link-status
 storm-control broadcast level 25.00
 storm-control multicast level 25.00
 spanning-tree portfast
 spanning-tree bpdug
And here is the actual running config on the interface in question:
Code:
Current configuration : 556 bytes
!
interface GigabitEthernet1/0/10
 description SecureCRT VanDyke Example
 switchport access vlan 2
 switchport mode access
 switchport port-security maximum 2
 switchport port-security
 switchport port-security aging time 2
 switchport port-security violation protect
 switchport port-security aging type inactivity
 load-interval 30
 power inline never
 speed 100
 srr-queue bandwidth limit 12
 no snmp trap link-status
 storm-control broadcast level 25.00
 storm-control multicast level 25.00
 spanning-tree portfast
 spanning-tree bpduguard enable
end
If I setup the script to do a full "show run", it captures many more lines than the above output, but it still doesn't capture the full output. There was one thing I was not sure about in the script example, and that is this part (lines 131-138):
Code:
                ' Check for success of command(s) (modify according your
                ' scenario), capturing the output of the command for storing in
                ' the excel spreadsheet.  Make sure that the success case is the
                ' first string in the array.
                vStringsToWaitFor = Array(_
                    strPrompt, _
                    "Type help or '?' for a list of available commands.")
                strResults = crt.Screen.ReadString(vStringsToWaitFor)
I don't know what "make sure that the success case is the first string in the array" means, but I have a feeling it's related to my issue.

Thanks for your time!
Reply With Quote
  #2  
Old 09-21-2016, 04:56 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 942
The code that captures the data is this line:

strResults = crt.Screen.ReadString(vStringsToWaitFor)

The ReadString() call is provided an array of strings, one of which is the "Type help or '?' for a list of available commands.", which clearly isn't being received so we know that it's not the issue. The other string is the value stored in the variable strPrompt. Hmm... logic would dictate that the next step would be to find out how this variable is populated.

So, looking for strPrompt = ... we see this:
Code:
    strPrompt = Trim(strPrompt)
...but before that, we also see this:
Code:
    strPrompt = crt.screen.Get(nRow, _
        0, _
        nRow, _
        crt.Screen.CurrentColumn - 1)
Well, let's take the old "messagebox" approach to debugging...

What do you see if after the strPrompt = Trim(strPrompt) line, you insert a new line of code to see what it is?
Code:
        crt.Dialog.MessageBox(strPrompt)
From there, if we see that strPrompt really does hold the actual prompt, then we need to troubleshoot down one avenue -- focusing on what's actually stored in the strResults variable immediately after the ReadString() call returns, and then working our way forward from there. If strPrompt doesn't hold what we expect (e.g. it's not the shell prompt with the hostname followed by a "#" character), then our troubleshooting efforts will take a different turn -- focusing instead on the efforts to use Screen.Get() to capture the shell prompt.

Given this information about how to move forward, what additional details do you uncover regarding your situation?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 09-22-2016, 03:54 PM
David0 David0 is offline
Registered User
 
Join Date: Sep 2016
Posts: 5
Hi Jake,

Thanks for your quick reply and your brief overview of the logical process of the script. I have added the message box line to return the value of strPrompt, and it returns the hostname of the device, aka the shell prompt as listed in the comments for that section of the code.
Code:
                    ' Loop until we actually see a line of text appear:
                    strPrompt = Trim(strPrompt)
		    crt.Dialog.MessageBox(strPrompt)
                    If strPrompt <> "" Then Exit Do

I went ahead and debugged the next step by confirming what strResults has immediately after the ReadString function is called, and strResults DOES in fact contain the entire output.

The issue appears to be immediately after the strCurLine function where strResults is modified in the following code:
strResults = Left(strResults, Len(strResults) - Len(strCurLine))

I checked the value of strCurLine immediately following this line in the code and it was the device's hostname / prompt. I also checked the Len(strCurLine) and that was 20. My devices hostname is 19 characters and there is a line break between the word "end" and the prompt, so that would make sense. I don't understand why the Left function is taking away an additional 14 characters from strResults (from "end" to "...spanning tree bpdug").

Anyways, I commented out the line where strResults is changed (quoted above) and the script worked fine!

I should have posted this in the very beginning, but I am running Windows 7 and Microsoft Office Plus 2013.
Reply With Quote
  #4  
Old 09-22-2016, 04:37 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 942
Nice work tracking down the issue and implementing the fix!

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 09-22-2016, 04:39 PM
David0 David0 is offline
Registered User
 
Join Date: Sep 2016
Posts: 5
I may have posted too soon about the script working fine... While it DOES work for the short output of the "show run int G1/0/10" command, the script is not capturing all the output for longer commands. It still manages to capture over several hundred lines, but for some reason it will not capture the full output, some of which ranges in the 2-3 thousand line length.

Are there any restrictions to using the script for such long command outputs?
Reply With Quote
  #6  
Old 09-22-2016, 06:26 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 942
There is a limit to what a string variable can hold in VBScript, but it's about 2 billion characters. So before we go there, what do the troubleshooting steps reveal?

Note: you may want to place data into the Clipboard, so that you can paste into Notepad (or whatever editor you desire), instead of using MessageBox() since MessageBox definitely truncates after something like 1024 characters.

You could use your MessageBox calls to say something like, "check the clipboard", for example:

Code:
  strResults = crt.Screen.ReadString(...)
  crt.Clipboard.Text = strResults
  crt.Dialog.MessageBox "Check clipboard for strResults"
This would be the "poor man's debugger" approach for long variables you need to "see".

--Jake

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #7  
Old 09-23-2016, 03:16 PM
David0 David0 is offline
Registered User
 
Join Date: Sep 2016
Posts: 5
Hi Jake,

I've followed your instructions to send the strResults string to the clipboard and all the data is there. I tested several different commands starting with a shorter one and finally ending with the longest output of them all, and the strResults variable/clipboard didn't have a problem holding the data. The longest one contained approximately 3450 lines, but the comment only picked up the first 755 lines of the output.

Any further ideas?
Reply With Quote
  #8  
Old 09-24-2016, 02:02 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 942
Quote:
Originally Posted by David0 View Post
...but the comment only picked up the first 755 lines of the output.
Can you clarify what you mean by the above?

What exactly do you see?

What, specifically is "the comment"?

What is the full output, and what's on line 755 where the output "ends"?

The more details you can provide about what you're seeing, the easier it may be to understand what's going on.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #9  
Old 10-04-2016, 03:17 PM
David0 David0 is offline
Registered User
 
Join Date: Sep 2016
Posts: 5
Hi Jake, please forgive my absence. I was out of office.

The script in question was written to capture all CLI output and add it to a comment bubble in excel that is linked to a single cell. Inside this comment box, only the first 755 lines of output from the CLI was included. In my test I tried capturing the output of "show mac address-table" which consists of several thousand MAC addresses in my network.

The comment box included the output up to (x's added for confidentiality):

........lines 1- ~750........
80 1005.caxx.xxxx DYNAMIC Po1
80 1005.caxx.xxxx DYNAMIC Po1

And then it stopped. The number on the left represents the VLAN number and that is how I know there should be more output as I have many higher VLAN IDs than that.

Since then, I have found another method using redirection, sed, grep, and awk so I'm not relying on this script at all anymore... but it would still be nice to figure out the issue for others that might encounter it.
Reply With Quote
  #10  
Old 10-04-2016, 05:21 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 942
Since you know that the variable you stored the data in as read in from crt.Screen.ReadString() included all the data from the command output (it was in the clipboard, as I recall you affirmed), then it means the limit is being imposed by Excel, which is outside the scope of SecureCRT's domain to control.

I would guess that there must be a limit to the number of characters that an Excel comment can hold -- this would not be something you'd be able to overcome in SecureCRT. That's a hard and fast limit that must be imposed by Excel, but I'm not an Excel expert and cannot say for sure. What I can say for a high degree of certainty is that SecureCRT is working as expected and it's scripting interface (crt.Screen.ReadString()) is also not the cause of the problem you're seeing in Excel.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
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 10:55 PM.