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-15-2019, 03:24 AM
Zander Zander is offline
Registered User
 
Join Date: Oct 2016
Posts: 10
Extracting Multiple Strings from Output / Text File

Hi all,

I'm currently writing a script that runs a command on a remote host and needs to pull out every occurrence of a certain string. I see two ways of doing this: #1 - All within the script or #2 - Exporting an output to a text file and then grepping (or the VBScript equivalent) for the lines that contain the string I'm looking for

So I'm running the equivalent of a
Code:
show run
and need to pull out every line that contains
Code:
ip route-static
as a single or, if it's easier, separate variables. Is this possible? I've had a long Google session and haven't been able to spot anything similar out there!

Thanks in advance,
Zander
Reply With Quote
  #2  
Old 05-15-2019, 10:53 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,830
Hi Zander,

I guess we need to refine our keywords then because I'm sure I've seen this many times in our forums.

Maybe not "ip route-static" being the trigger phrase, but definitely the process described is similar.

Quote:
and need to pull out every line that contains ...
What will you do with the data you pull out? Are you going to write it to a file? Use it in some way within the script?

As a starting point I always like to give the link to the scripting manual. In Chapter 4: Reading Data from Remote Machines (Section 4.3 specifically) are examples of various methods for capturing the data, such as using Get(), Get2() and ReadString(). Then there's an entire section on VBS functions designed to extract the data, such as InStr(), Split(), etc.

Once I have a better understanding of the overall objective, I'll see if I can locate any other posts with relevant info.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 05-17-2019, 02:30 AM
Zander Zander is offline
Registered User
 
Join Date: Oct 2016
Posts: 10
Quote:
Originally Posted by bgagnon View Post
Hi Zander,

I guess we need to refine our keywords then because I'm sure I've seen this many times in our forums.

Maybe not "ip route-static" being the trigger phrase, but definitely the process described is similar.


What will you do with the data you pull out? Are you going to write it to a file? Use it in some way within the script?

As a starting point I always like to give the link to the scripting manual. In Chapter 4: Reading Data from Remote Machines (Section 4.3 specifically) are examples of various methods for capturing the data, such as using Get(), Get2() and ReadString(). Then there's an entire section on VBS functions designed to extract the data, such as InStr(), Split(), etc.

Once I have a better understanding of the overall objective, I'll see if I can locate any other posts with relevant info.
Apologies bgagnon, poor wording on my part there - I'm not the most advanced when it comes to this sort of thing and I haven't been able to spot something that relates to me. However that may be because I've not fully understood what I was reading

I need to manipulate the output and then write it to a file. Basically I would like to pull out every instance in the configuration that contains "ip route-static", remove some parts of that line and then write that to file. I know how to write a string to a file and I'm able to utilise the functions used in this example script to pull out the first instance of "ip route-static" but obviously I'd like to pull out all instances. If it helps at all, the line itself would look like this
Code:
ip route-static vpn-instance [VPN] [IP Pool Network Address] [Subnet mask] [Interface] description [description]
(If there are multiple lines then they will look the same, just one after another). So what I'd like to be left with is just the IP Pool Network Address + Subnet mask to write to a file

Thanks for taking the time to help me out, it's greatly appreciated
Reply With Quote
  #4  
Old 05-17-2019, 09:51 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,830
Hi Zander,

Quote:
ip route-static vpn-instance [VPN] [IP Pool Network Address] [Subnet mask] [Interface] description [description]
Unless you are well-versed in regular expression syntax yourself, I need to see actual output.

If that's sensitive data, please send an email to support@vandyke.com and reference "Attn Brenda - Forum Thread #13545".

We are quite busy right now and any scripting assistance needs to be in free cycles so it may be a few days before I have any suggestions.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 05-21-2019, 08:07 AM
Zander Zander is offline
Registered User
 
Join Date: Oct 2016
Posts: 10
Quote:
Originally Posted by bgagnon View Post
Hi Zander,


Unless you are well-versed in regular expression syntax yourself, I need to see actual output.

If that's sensitive data, please send an email to support@vandyke.com and reference "Attn Brenda - Forum Thread #13545".

We are quite busy right now and any scripting assistance needs to be in free cycles so it may be a few days before I have any suggestions.
Haha, that's fair enough! In that case it'd be...
Code:
ip route-static vpn-instance vpn1-test 192.168.0.0 255.255.255.0 ge1/0/0 description test
Thank you again for the help, it's greatly appreciated!
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 -6. The time now is 04:57 PM.