Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-11-2007, 04:11 AM
amcq1010 amcq1010 is offline
Registered User
 
Join Date: Mar 2007
Posts: 7
Any way to speed up "ReadString"??

Hello -

I've been testing out quite a bit of the different methods for entering commands into a device, then capturing all the output from that command.

I started out with the examples for Get and Get2,.. but, just didn't seem to to what I wanted it to.

I finally started looking at the ReadString object, and have found it to be very close to what I'm looking for.

I guess you could say I'm looking to mimic the "Expect" methods for entering commands, and then getting all output after that, until some pre-determined text appears (such as command prompt).

With the ReadString, I've setup the following.

Code:
    $crt->Screen->Send("show data with tons of output\015");
    while ($Finished == 0)
    {
      $CurrChar = $crt->Screen->ReadString;
      if ($CurrChar =~ /\015/)
      {
        push (@Lines, $Total_Output);
        $Total_Output = "";
      }
      else { $Total_Output = "$Total_Output$CurrChar"; }
      if ($CurrChar =~ /#/) { $Finished = 1; } 
    }
    
    foreach $line (@Lines)
    {
    .... I then process the lines however I wish
    }

What I'm faced with is that this takes quite a bit of time to execute.
Normally, when I just execute the command within the terminal.. it displays top to bottom in about 1 second.
However, when the "ReadString" is being used, it is much slower.. somewhere around 5 seconds.

This may not sound like much.. BUT, after executing the above, I extract about 25-50 lines with a Hex Value on them, that I then re-enter into the terminal, so that I get more details about each item. We now end up with 25-50 more commands... each taking 4-5 times longer to execute than normal.


I'm just looking to see if there's any tricks I can do to possibly have SecureCRT "Not" read each character individually.. but rather a whole chunk of output.

Such as.. I enter the command, and then tell it to "start capture" and continue capture until "text string" appears. (I realize that this is exactly what I'm doing in my code above.. but, I'd like to get away from the character-by-character parsing of the data.. and into larger chunks.)


Thanks!
Reply With Quote
  #2  
Old 08-13-2007, 12:23 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Amcq1010,

The readstring function will slow SecureCRT's down quite a bit and there isn't a method to speed this process up currently.

I have entered a request in our feature request database for an option to be able to issue a command and then capture all the data until a certain string is found.

If this option is added to a future release of SecureCRT, a post will be made here.

If you would prefer to be contacted via email, please send me a message and reference this forum thread (2422).
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #3  
Old 02-23-2017, 09:33 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
This is still an issue?
Reply With Quote
  #4  
Old 02-23-2017, 10:02 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Rhudi,

It may help for me to have a little more context. What is it you are having trouble with or attempting to do?

If you are wanting to be able to enter command and log the results we have several example scripts available.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by ekoranyi; 02-23-2017 at 02:11 PM.
Reply With Quote
  #5  
Old 02-23-2017, 01:48 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
I was searching for a way to speed up ReadString. As the screen fills with multiple lines, the output gets painfully slow.

I have code like this:
Code:
    objTab.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
    objTab.Screen.Send vbCr                   ' Send <CR>
    objTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    strDeviceData = ""
    For Each strCommand in arrCommandLines
        '            "show-me -t <TYPE> -h <HOST> -c <CMD>"
        strCommand = Replace(Replace(Replace(strShowMe, "<TYPE>", strHostType), _
                                     "<HOST>", strDevice), _
                             "<CMD>", Chr(34) & strCommand & Chr(34))

        objTab.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
        objTab.Screen.Send vbCr                   ' Send <CR>
        objTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
        objTab.Screen.Send strCommand & vbCr  ' Send command to the device.
        strDeviceData = strDeviceData & vbCrlf & vbCrlf & _
                        Replace(objTab.Screen.ReadString(strPrompt), vbCr & vbCr, vbCr)
    Next
It hurts when I'm receiving a lot of output (a large router config).

I tried it this way (which seemed to work fine, until a couple of recent failures):

Code:
    ScriptTab.Screen.Send vbCr                   ' Send <CR>
    ScriptTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    For Each strCommand in arrCommandLines
        '            "show-me -t <TYPE> -h <HOST> -c <CMD>"
        strCommand = Replace(Replace(Replace(strShowMe, "<TYPE>", strHostType), _
                                     "<HOST>", strDevice), _
                             "<CMD>", Chr(34) & strCommand & Chr(34))
        ScriptTab.Screen.Send strCommand & vbCr  ' Send command to the device.
        ScriptTab.Screen.WaitForString strPrompt ' Wait for the prompt.
    Next
    ScriptTab.Screen.Send vbCr                   ' Send <CR>
    ScriptTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    crt.Window.Activate
    ScriptTab.Screen.SendSpecial("MENU_SELECT_ALL")
    ScriptTab.Screen.SendSpecial "MENU_COPY"
    strDeviceData = crt.Clipboard.Text
    crt.Clipboard.Text = ""
This second way sometime returns nothing (even tho I see a screen full of text).
Reply With Quote
  #6  
Old 02-23-2017, 02:00 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
The scripts examples in your previous response are intriguing. I see items that solve other issues that I have in my scripts. I will post any solution I work out.
Reply With Quote
  #7  
Old 02-23-2017, 02:11 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Rhudi,

It may take me some time to review ReadString and see if there is a way we could improve performance.

In the mean time we have an example script for saving Cisco configurations. It can save either running-config or the startup-config.

I hope this helps you while I review ReadString.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #8  
Old 02-23-2017, 03:52 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
Ok...

The rest of my coding is in Excel VB. I know that code. Switching to Python is a learning curve I don't want right now.

This feels clunky, but seems to work:
Code:
    objTab.Screen.Send vbCr                   ' Send <CR>
    objTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    For Each strCommand in arrCommandLines
        '            "show-me -t <TYPE> -h <HOST> -c <CMD>"
        strCommand = Replace(Replace(Replace(strShowMe, "<TYPE>", strHostType), _
                                     "<HOST>", strDevice), _
                             "<CMD>", Chr(34) & strCommand & Chr(34))
        objTab.Screen.Send strCommand & vbCr  ' Send command to the device.
        objTab.Screen.WaitForString strPrompt ' Wait for the prompt.
        crt.Sleep (2500)
    Next
    objTab.Screen.Send vbCr                   ' Send <CR>
    objTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    crt.Sleep (2500)
    objTab.Screen.SendSpecial("MENU_SELECT_ALL")
    crt.Sleep (2500)
    objTab.Screen.SendSpecial("MENU_COPY")
    strDeviceData = crt.Clipboard.Text
The "crt.Sleep (2500)" seems to help.
Reply With Quote
  #9  
Old 02-24-2017, 07:47 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
Ultimately, I need to do this (which seems to have fixed the issue):
Code:
    objTab.Screen.Send vbCr                   ' Send <CR>
    objTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    For Each strCommand in arrCommandLines
        '            "show-me -t <TYPE> -h <HOST> -c <CMD>"
        strCommand = Replace(Replace(Replace(strShowMe, "<TYPE>", strHostType), _
                                     "<HOST>", strDevice), _
                             "<CMD>", Chr(34) & strCommand & Chr(34))
        objTab.Screen.Send strCommand & vbCr  ' Send command to the device.
        objTab.Screen.WaitForString strPrompt ' Wait for the prompt.
        crt.Sleep (250)
    Next
    objTab.Screen.Send vbCr                   ' Send <CR>
    objTab.Screen.WaitForString strPrompt     ' Wait for the prompt.
    crt.Sleep (500)
    intLoopTries = 5 ' Try 5 times
    Do
        objTab.Screen.SendSpecial("MENU_SELECT_ALL")
        crt.Sleep (500)
        objTab.Screen.SendSpecial("MENU_COPY")
        strDeviceData = crt.Clipboard.Text
        Select Case strDevice
            Case strDeviceData ' FAILURE
                crt.Sleep (1500) ' Take a breath before trying again
                intLoopTries = intLoopTries - 1
            Case Else ' We got data
                intLoopTries = 0
        End Select
    Loop Until intLoopTries = 0
It seems that for some reason, the objTab.Screen.SendSpecial("MENU_SELECT_ALL")
command will sometimes just not actually select anything.
When that happens, what was in the copy buffer to begin with is still there and I can use that match to loop. As soon as it doesn't match, I assume I'm good.
Reply With Quote
  #10  
Old 02-24-2017, 08:05 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
Ok... I accidentally figured out what was wrong. If SecureCRT looses focus, the objTab.Screen.SendSpecial("MENU_SELECT_ALL") command fails.

How do I tell SecureCRT to regain focus?
Reply With Quote
  #11  
Old 02-24-2017, 08:26 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 97
And, so I finally believe I fixed it...

Here is the core of my Do-Loop:
Code:
    Do
        Select Case crt.Window.Active
            Case True
                objTab.Screen.SendSpecial("MENU_SELECT_ALL")
                objTab.Screen.SendSpecial("MENU_COPY")
                strDeviceData = crt.Clipboard.Text
                Select Case strDevice
                    Case strDeviceData ' FAILURE
                        crt.Sleep (1500) ' Take a breath before trying again
                        intLoopTries = intLoopTries - 1
                    Case Else ' We got data
                        intLoopTries = 0
                End Select
            Case False
                crt.Window.Activate
        End Select
    Loop Until intLoopTries = 0
crt.Window.Active / crt.Window.Activate seems to be the key.
Reply With Quote
  #12  
Old 02-24-2017, 09:38 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Rhudi,

It looks like it's been a busy morning for you.

Sorry I wasn't of more help but I'm glad you found a solution.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

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:39 PM.