VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   vbs script first-match-and-stopped (https://forums.vandyke.com/showthread.php?t=12863)

truebeatles 10-18-2017 11:15 AM

vbs script first-match-and-stopped
 
Hi Van,

I need you help in doing some script.

Im doing some search in a server files to find IP address match.

For example:

crt.Screen.Send "isearch -w 172.30.16.226" & chr(13)
crt.Screen.WaitForString "-bash-3.2$"
crt.Screen.Send "isearch -w 172.30.16.227" & chr(13)
crt.Screen.WaitForString "-bash-3.2$"

The problem with this script is that i need the script stop on first match e continuous to the next command.

May you give some help?

Thanks in advance,

Alexandre Guia Ferraro

bgagnon 10-18-2017 11:50 AM

Hi Alexandre,

I am not sure I understand what you are trying to accomplish.

Quote:

The problem with this script is that i need the script stop on first match e continuous to the next command.
I assume "-bash-3.2$" is the prompt that the remote sends after the command completes, so first match of what?

In general, you can exit early if your code lends itself well to being in a looping construct. Or it may be as simple as an If/Then statement:

Code:

If "string found" Then
' Do work
End If

Do you need to capture the results of the isearch command in a variable? If so, use ReadString(). And then parse that data looking for the match? If so, you can use a For/Next loop (and use InStr to detect the string) and Exit For once the match is found.

truebeatles 10-18-2017 12:15 PM

Quote:

Originally Posted by bgagnon (Post 48271)
Hi Alexandre,

I am not sure I understand what you are trying to accomplish.


I assume "-bash-3.2$" is the prompt that the remote sends after the command completes, so first match of what?

You are right, it is the prompt that the remote sends at the end. Im looking to find some rules in firewalls using that IP address.

In general, you can exit early if your code lends itself well to being in a looping construct. Or it may be as simple as an If/Then statement:

Code:

If "string found" Then
' Do work
End If

Do you need to capture the results of the isearch command in a variable? If so, use ReadString(). And then parse that data looking for the match? If so, you can use a For/Next loop (and use InStr to detect the string) and Exit For once the match is found.

Yes, i need to know only the first match. This situation stop me to reuse that ip address until the rules will be clear.

I have been studing the ReadString(). Now, I will do some test.

Thanks again.

Alexandre.

truebeatles 10-18-2017 01:05 PM

Quote:

Originally Posted by truebeatles (Post 48273)
You are right, it is the prompt that the remote sends at the end. Im looking to find some rules in firewalls using that IP address.

Yes, i need to know only the first match. This situation stop me to reuse that ip address until the rules will be clear.

I have been studing the ReadString(). Now, I will do some test.

Thanks again.

Alexandre.

You are right, it is the prompt that the remote sends at the end. Im looking to find some rules in firewalls using that IP address.

Yes, i need to know only the first match. This situation stop me to reuse that ip address until the rules will be clear.

I have been studing the ReadString(). Now, I will do some test.

Thanks again.

bgagnon 10-18-2017 01:09 PM

Hi Alexandre,

So a super simplistic example is:

Code:

strText = crt.Screen.ReadString("-bash-3.2$")
vLines = Split(strText, vbcrlf)
For line in vLines
    If InStr(line, "string_searching_for") > 0 Then
    ' Do work
    Exit For
Next

Good Luck! :)

truebeatles 10-18-2017 01:12 PM

Quote:

Originally Posted by bgagnon (Post 48276)
Hi Alexandre,

So a super simplistic example is:

Code:

strText = crt.Screen.ReadString("-bash-3.2$")
vLines = Split(strText, vbcrlf)
For line in vLines
    If InStr(line, "string_searching_for") > 0 Then
    ' Do work
    Exit For
Next

Good Luck! :)

Tks Brenda,

I will report back.


All times are GMT -6. The time now is 04:33 PM.