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-18-2017, 11:15 AM
truebeatles truebeatles is offline
Registered User
 
Join Date: Oct 2017
Posts: 4
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
Reply With Quote
  #2  
Old 10-18-2017, 11:50 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,937
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-18-2017, 12:15 PM
truebeatles truebeatles is offline
Registered User
 
Join Date: Oct 2017
Posts: 4
Quote:
Originally Posted by bgagnon View Post
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.
Reply With Quote
  #4  
Old 10-18-2017, 01:05 PM
truebeatles truebeatles is offline
Registered User
 
Join Date: Oct 2017
Posts: 4
Quote:
Originally Posted by truebeatles View Post
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.
Reply With Quote
  #5  
Old 10-18-2017, 01:09 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,937
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!
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 10-18-2017, 01:12 PM
truebeatles truebeatles is offline
Registered User
 
Join Date: Oct 2017
Posts: 4
Quote:
Originally Posted by bgagnon View Post
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.
Reply With Quote
Reply

Tags
#first-matchvbscript


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 08:49 PM.