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 05-28-2014, 11:12 PM
akulee0701 akulee0701 is offline
Registered User
 
Join Date: May 2014
Posts: 2
Help needed on instr(vSubmatches(2),array)

Hi All,

i was trying to use compare using instr. i was able to pull the data and was able to perform the scripts if instr(vSubmatches(2), "10.10.10.10"). i know the scripts now work when it look for 10.10.10.10 it will be do crt.Screen.Send "sh run | i " & vSubmatches(I_PID) & vbcr which it will match the interfaces.

QUESTION IS : is there anyway that i can compare vSubmatches(2) upon a string of array.

i have 100 devices which will have different ip address. highlighted below in red is the one that i need to replace it will an array of ip address...

i am using win 7 64 bit and Version 5.5.1 (build 407)

thank you so much.... !!! I am sorry if this has been responded previously.

below is my scripts :

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

Sub Main()
crt.Screen.Synchronous = True
szShellPrompt = "R1#"
Set re = new RegExp
re.Global = True
re.IgnoreCase = True
re.Multiline = True
re.Pattern = "(\S+)(\s+)(\S+)"
CONST I_PID = 0, I_CMD = 1, test = 2
redim vSubmatches(3)

crt.Screen.Send "sh ip int bri" & vbcr

Do
nResult = crt.Screen.WaitForStrings (vbcr, szShellPrompt)
if nResult = 2 then exit do


szLine = Trim(crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns))
trim (szLine)

if re.Test(szLine) then
Set Matches = re.Execute(szLine)
For each Match in Matches
if Match.Submatches.Count > 0 then
For nIndex = 0 to Match.Submatches.Count - 1
vSubmatches(nIndex) = Match.Submatches(nIndex)
Next
end if
exit for
Next
if Instr(vSubmatches(2), "10.10.10.10") > 0 then ' <------- this is where i want to replace to an array
crt.Screen.Send "sh run | i " & vSubmatches(I_PID) & vbcr
end if
end if
Loop
End Sub




below is the output :

R1#sh ip int bri
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 10.10.10.10 YES manual administratively down down
FastEthernet0/1 unassigned YES unset administratively down down
R1#sh run | i FastEthernet0/0
interface FastEthernet0/0
Reply With Quote
  #2  
Old 05-29-2014, 01:24 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,437
Hello akulee0701,

This is more a VB scripting question than it is a SecureCRT question.

That is also a pretty old version of SecureCRT. Windows 7 was not officially supported until version 6.5.

You may want to check your upgrade eligibility here.

Do you just want to confirm if the IP is found in the file?

Or do you actually want to get the data from the file?

If the second option, you should read the file in and then add it to a dictionary (collection). That should make it easy to access the needed data.

I have attached an example script that, while not specific to your task, will illustrate how to use the Dictionary object available in VBScript.
Attached Files
File Type: txt AliasSearchForHostUsingDictionary.vbs.txt (2.6 KB, 294 views)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 06-02-2014, 08:03 PM
akulee0701 akulee0701 is offline
Registered User
 
Join Date: May 2014
Posts: 2
Question

hi there,

I wish to do the second option but unfortunately when i tried to run ur scripts it gave me some error.

" subscripts out of range:'[number:0]'
line 26


can anyone help me on this ?

I am very new to scripting and will appreciate if someone could help.
Reply With Quote
  #4  
Old 06-03-2014, 09:40 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,437
Hello akulee0701,

Quote:
I wish to do the second option but unfortunately when i tried to run ur scripts it gave me some error.
I am not sure why you would run the example script.

The goal is to incorporate the code for creating a dictionary object (from the example script) into *your* script.

Did you do that?

If so, please send a copy of your script to support@vandyke.com. Please reference "Attn Brenda - Forum Thread #11529" in the subject line.
NOTICE: The requested troubleshooting data may include sensitive information (usernames, passwords, publicly-accessible host names or IP addresses, etc.).

Please redact sensitive information that would not be appropriate for email communication prior to sending the requested information.

If there is sensitive information that must be conveyed in order to provide a complete picture of the scenario you're facing, please let us know and we will set up a secure upload mechanism that can be used.
__________________
Thanks,
--Brenda

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

Tags
array , comparison of array , instr


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 10:09 AM.