VanDyke Software Forums

Go Back   VanDyke Software Forums > Scripting
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-19-2017, 06:08 AM
hooknife hooknife is offline
Registered User
 
Join Date: Mar 2007
Posts: 14
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
Reply With Quote
  #2  
Old 05-19-2017, 08:01 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 98
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?
__________________
Thanks,
--Eric

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

Last edited by ekoranyi; 05-19-2017 at 09:28 AM.
Reply With Quote
  #3  
Old 05-22-2017, 06:47 AM
thera34 thera34 is offline
Registered User
 
Join Date: May 2015
Posts: 3
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
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 -7. The time now is 05:59 PM.


copyright 1995-2015 VanDyke Software, Inc.