VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   How do impalement a "or" operation? (https://forums.vandyke.com/showthread.php?t=12707)

hooknife 05-19-2017 07:08 AM

How do impalement a "or" operation?
 
This seems like it should be easy...

All of the equipment I work on has a "#" or "# " in the prompt when you're fully logged in. I just want my script to use a logical and/or operation and fire off if it sees "#" or "# " in the prompt.

I can get the below script to run if "# " (note the space) exists but it wont run if the prompt is missing the space after the # symbol.

Below is my script.

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

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
crt.Screen.WaitForString "# "
crt.Screen.Send "term pager 0" & chr(13)
crt.Screen.Send "term length 0" & chr(13)
crt.Screen.Send "show run" & chr(13)
crt.Screen.Send "show start" & chr(13)
crt.Screen.Send "term pager 48" & chr(13)
crt.Screen.Send "ter length 48" & chr(13)
End Sub

ekoranyi 05-19-2017 09:01 AM

Hi hooknife,

crt.Screen.WaitForString "#" (no space) should cover both instances since it finds the # regardless of what is after it. Is that not the behavior you see?

Another option would be to create and array of values you would like to wait for and use crt.Screen.WaitForStrings.

Code:

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

crt.Screen.Synchronous = True

WaitFors = Array("Value1","Value2 ")

Sub Main

        crt.Screen.WaitForStrings(WaitFors)

        crt.Dialog.MessageBox("Found it!")

End Sub

* If your values contain substrings of each other there will be problems. If you add "#" and "# " the "# " will never be found, SecureCRT will match with the "#" before the " " is added.

Does this help?

thera34 05-22-2017 07:47 AM

Hello,

Instead of waiting for your "# ", I prefer to read and store first the device's full prompt then after I issue a Screen.Send something, I just Screen.WaitForString for that prompt like in the below example.
The GetShellPrompt Function I found it somewhere on the internet (maybe in this exact forum, cannot remember).

Code:

#$language = "VBScript"
#$interface = "1.0"
Dim strPrompt
' some other stuff

Sub Main

        Do
                bCursorMoved = crt.Screen.WaitForCursor(1)                                                                                                                ' I instruct SecureCRT to wait until cursor stops moving for 1 second (Can be increased for slower machines)
        Loop Until bCursorMoved = False
        strPrompt = GetShellPrompt()                                                                                                                                                ' Get Terminal Server's (or other devices) prompt

' Now some misc code
crt.Screen.Send "term length" & chr(13)
crt.Screen.WaitForString strPrompt
' and so on
End Sub

' -----------------------------------------------------------------------------
' GetShellPrompt - determine the shell's prompt
' -----------------------------------------------------------------------------
Function GetShellPrompt()
                                                                                                                                                                ' Heuristically determine the shell's prompt.  Crt.Screen.Synchronous must
                                                                                                                                                                ' already have been set to True.  In general, Crt.Screen.Synchronous should
                                                                                                                                                                ' be set to True immediately after a successful crt.Session.Connect().  In
                                                                                                                                                                ' This script, SecureCRT should already be connected -- otherwise, a script
                                                                                                                                                                ' error will occur.
    Do                                                                                                                                                        ' Simulate pressing "Enter" so the prompt appears again...
        crt.Screen.Send vbcr
                                                                                                                                                                ' Attempt to detect the command prompt heuristically by waiting for the
                                                                                                                                                                ' cursor to stop moving... (the timeout for WaitForCursor above might
                                                                                                                                                                ' not be enough for slower- responding hosts, so you will need to adjust
                                                                                                                                                                ' the timeout value above to meet your system's specific timing
                                                                                                                                                                ' requirements).
        Do
            bCursorMoved = crt.Screen.WaitForCursor(1)
        Loop Until bCursorMoved = False
                                                                                                                                                                ' Once the cursor has stopped moving for about a second, it's assumed
                                                                                                                                                                ' it's safe to start interacting with the remote system. Get the shell
                                                                                                                                                                ' prompt so that it's known what to look for when determining if the
                                                                                                                                                                ' command is completed. Won't work if the prompt is dynamic (e.g.,
                                                                                                                                                                ' changes according to current working folder, etc.)
        nRow = crt.Screen.CurrentRow
        strPrompt = crt.Screen.Get(nRow, 0, nRow, crt.Screen.CurrentColumn - 1)
                                                                                                                                                                ' Loop until a line of non-whitespace text actually appears:
        strPrompt = Trim(strPrompt)
        If strPrompt <> "" Then Exit Do
    Loop
   
    GetShellPrompt = strPrompt
   
End Function



All times are GMT -6. The time now is 02:35 AM.