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 10-13-2015, 01:09 PM
benitocamela benitocamela is offline
Registered User
 
Join Date: Sep 2015
Posts: 5
output delay after crt.Screen.Send

Hi

Sometimes, after send a command with crt.Screen.Send "COMMAND" & chr(13), i'm wait for a specific string, ex: crt.Screen.WaitForString "RESULT".

But that specific string it's situated between another strings, this does sometimes the order crt.Screen.WaitForString
not read the string expected.


I guess this happens because the router send the outout very fast and the script can not read crt.Screen.WaitForString "RESULT"

is there any way to delay the output in secure.crt.

Regards
Reply With Quote
  #2  
Old 10-13-2015, 01:33 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
If you haven't done so already, I'd suggest you spend some time reading through the scripting guide.

Even if you're not using VBScript as your SecureCRT automation language, the concepts described in chapters 4 and 5 can be helpful for understanding concepts like "synchronous".

In general, you'll want to make sure that at the top of your script (or immediately following any Connect...() calls), you set the Screen object's "Synchronous" property to true, which will make sure that data doesn't get displayed to the screen before you make any calls designed to wait for or capture the data.

In your specific case, it would be helpful to know more details about the situation in which the problem occurs, so that a specific suggestion can be made towards a resolution.

Can you provide the specific text you're seeing, what you're waiting for and how, specifically, your script is failing?

--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 10-14-2015, 12:33 PM
benitocamela benitocamela is offline
Registered User
 
Join Date: Sep 2015
Posts: 5
Hi Jack

Im set the Screen object's "Synchronous" property to true, you can see it in the script:

Quote:
# $language = "VBScript"
# $interface = "1.0"

Const ForReading = 1
Const ForWriting = 2

Sub Main

Dim logfile
logfile = "C:\TEMP\mysession.log"
crt.Session.LogFileName = logfile

Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")
'crt.Session.Log true
' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
'
Set file = fso.OpenTextFile("C:\MY_ROUTERS.txt", ForReading, False)
crt.Screen.Synchronous = True
crt.Screen.Clear

Do while file.AtEndOfStream <> True

str = file.Readline
' Send the line with an appended CR
crt.Screen.Send str & VbCr
crt.sleep 1000


crt.Screen.WaitForString "assword:",2
' Send your password followed by a carriage return
crt.Screen.Send "My_PASSWORD" & VbCr

crt.Screen.WaitForString ">"
crt.Screen.Send "COMMAND_1" & VbCr
crt.Screen.WaitForString ">"

crt.Screen.Send "CHECK_STATUS" & VbCr

nTimeout = 5
Do While crt.Screen.WaitForString ("busy", nTimeout)
crt.sleep 60000
crt.Screen.Send "CHECK_STATUS" & VbCr
Loop
crt.Screen.Send VbCr
crt.Screen.WaitForStrings ">"
crt.Screen.Send "exit" & VbCr

crt.Screen.WaitForString "~]$"

Loop

End sub
When i send crt.Screen.Send "CHECK_STATUS" & VbCr, im wait the word busy to start the loop until the router status is different than busy.

Text format where the word is busy after send the check status command, is:

Quote:
TASK JOBS QUEUED: [OK]
OPERATIONS QUEUED: [OK]
CPU: 0.05% < 50% [OK]

Router resources are busy

Regards
Reply With Quote
  #4  
Old 10-14-2015, 06:01 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,031
The risk I see with your code is that you're waiting for "busy", but you're also passing in a timeout parameter of 5 seconds.

Is there ever a time where you won't see "busy" within 5 seconds of issuing the check-status command? If so, you'll need to up your timeout to accommodate the worst of cases.

Another approach would be to wait for more than one string, one for the failure (busy) case, and another for the success case.

If the device is not "busy", what shows up in the output of the command instead? In other words, is there something you see on the screen that tells you it's *not* busy as a result of running the check-status command? If so, then you can tell SecureCRT to wait for multiple strings, and tell you which one it found, so you can branch on that data to either exit your loop or continue waiting, or call your Aunt Sandra, or whatever you desire .

For the sake of example let's say that your router says "Router ready" instead of "Router resources are busy" when it's, well, ready instead of busy. Your loop would look like this instead (throwing in a little bit of extra cool-ness in there for fun ):

Code:
nTimeOut = 5
nSleepTime = 60
Do
    nResult = crt.Screen.WaitForStrings("busy", "ready", nTimeOut)
    Select Case crt.Screen.MatchIndex
        Case 1
            For nCounter = 0 to nSleepTime - 1
                crt.Session.SetStatusText "Found 'busy'; Sleeping for " & nSleepTime - nCounter & " seconds..."
                crt.sleep 1000
            Next
            crt.Screen.Send "CHECK_STATUS" & VbCr
            crt.Screen.WaitForString "CHECK_STATUS"
            
        Case 2
            ' Ah! found "ready"; time to exit the loop
            crt.Session.SetStatusText "Found 'ready'; exiting loop"
            Exit Do
            
        Case 0
            ' In this case, we timed out...
            crt.Session.SetStatusText "Timed out waiting for strings."
            crt.Dialog.MessageBox "Timed out after " & _
                nTimeOut & " seconds." & vbcrlf & _
                "You will want to increase your time out, or add " & _
                "additional strings to look for."
            Exit Do
        
        Case Else
            ' In this case, you have a mismatch between the number of
            ' strings you're passing to WaitForStrings(), and the number
            ' of case statements you've written code to handle. Ooops.
            ' Time to write another case statement!
            crt.Dialog.MessageBox _
                "Oops! Time to write another case statement for string #" & _
                crt.Screen.MatchIndex
            Exit Do
    End Select
    
Loop
--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 04:04 PM.