Community discussions

 
lz1dsb
Member Candidate
Member Candidate
Topic Author
Posts: 222
Joined: Wed Aug 07, 2013 11:48 am

Filtering outputs on print commands? How?

Wed Aug 20, 2014 5:45 pm

I don't know if this is the right place to put this...

How can I filter the output of any print command in RouterOS?
for example: ip route print - how can I get only the connected, static, etc... it does have embedded filter for BGP and OSPf though - it works.
But how can I flexibly define what I want to be displayed? I'm running full table BGP now and it's really needed.

I also need to filter output on the ip firewall connection print command.

I know there's the 'where' option, but it does not seem to work, or very likely I don't use it properly.
There's also a 'find' option, what's the difference?

Is there a nice guide explaining these command options?
 
User avatar
payday
Member Candidate
Member Candidate
Posts: 233
Joined: Thu Aug 16, 2012 11:05 pm

Re: Filtering outputs on print commands? How?

Thu Aug 21, 2014 12:32 am

How can I filter the output of any print command in RouterOS?
for example: ip route print - how can I get only the connected, static, etc... it does have embedded filter for BGP and OSPf though - it works.
But how can I flexibly define what I want to be displayed? I'm running full table BGP now and it's really needed.
Is there a nice guide explaining these command options?
You probably put: "/ip route print where ?" in the console (with question mark) and you got shorter list of options:
                 whitespace
        <value>  literal value that consists only of digits, letters and 
                 characters ._
              !  logical negation
              "  start of quoted string
              $  substitution
              (  start of subexpression
              -  unary minus
              >  quote
              [  start of command substitution
              {  start of array value
              ~  bit inversion
            bgp  Find or not BGP routing protocol
  check-gateway  Whether all nexthops of this route are checking reachability 
                 of gateway by sending arp requests every 10 seconds
        comment  Short description of the item
       disabled  Defines whether item is ignored or used
       distance  Administrative distance of the route
    dst-address  Destination address
           ospf  Find or not OSPF routing protocol
            rip  Find or not RIP routing protocol
   routing-mark  It's used for policy-routing
Type in the console: "/ip route print where <tab>" (press [TAB] at the end) and you will get full list of options:
active                bgp-weight     gateway-status  routing-mark 
bgp                   blackhole      mme             scope        
bgp-as-path           check-gateway  ospf            static       
bgp-atomic-aggregate  comment        ospf-metric     target-scope 
bgp-communities       connect        ospf-type       type         
bgp-ext-communities   disabled       pref-src        unreachable  
bgp-local-pref        distance       prohibit        vrf-interface
bgp-med               dst-address    received-from   
bgp-origin            dynamic        rip             
bgp-prepend           gateway        route-tag       
Now you see options you are looking for (connect, static).
To see static routes type:
/ip route print where static=yes
To see connected routes type:
/ip route print where connect=yes
You can combine options to filter what you want:
/ip route print where static=yes and active=yes
[TAB] key will always give you list of possible options.
 
lz1dsb
Member Candidate
Member Candidate
Topic Author
Posts: 222
Joined: Wed Aug 07, 2013 11:48 am

Re: Filtering outputs on print commands? How?

Thu Aug 21, 2014 11:46 am

How can I filter the output of any print command in RouterOS?
for example: ip route print - how can I get only the connected, static, etc... it does have embedded filter for BGP and OSPf though - it works.
But how can I flexibly define what I want to be displayed? I'm running full table BGP now and it's really needed.
Is there a nice guide explaining these command options?
You probably put: "/ip route print where ?" in the console (with question mark) and you got shorter list of options:
                 whitespace
        <value>  literal value that consists only of digits, letters and 
                 characters ._
              !  logical negation
              "  start of quoted string
              $  substitution
              (  start of subexpression
              -  unary minus
              >  quote
              [  start of command substitution
              {  start of array value
              ~  bit inversion
            bgp  Find or not BGP routing protocol
  check-gateway  Whether all nexthops of this route are checking reachability 
                 of gateway by sending arp requests every 10 seconds
        comment  Short description of the item
       disabled  Defines whether item is ignored or used
       distance  Administrative distance of the route
    dst-address  Destination address
           ospf  Find or not OSPF routing protocol
            rip  Find or not RIP routing protocol
   routing-mark  It's used for policy-routing
Type in the console: "/ip route print where <tab>" (press [TAB] at the end) and you will get full list of options:
active                bgp-weight     gateway-status  routing-mark 
bgp                   blackhole      mme             scope        
bgp-as-path           check-gateway  ospf            static       
bgp-atomic-aggregate  comment        ospf-metric     target-scope 
bgp-communities       connect        ospf-type       type         
bgp-ext-communities   disabled       pref-src        unreachable  
bgp-local-pref        distance       prohibit        vrf-interface
bgp-med               dst-address    received-from   
bgp-origin            dynamic        rip             
bgp-prepend           gateway        route-tag       
Now you see options you are looking for (connect, static).
To see static routes type:
/ip route print where static=yes
To see connected routes type:
/ip route print where connect=yes
You can combine options to filter what you want:
/ip route print where static=yes and active=yes
[TAB] key will always give you list of possible options.
Thank you!
I have somehow missed the <Tab> option...
And what about the find option? Can I also use it for custom filtering? I cannot seem to get a hand of the syntax...
 
User avatar
payday
Member Candidate
Member Candidate
Posts: 233
Joined: Thu Aug 16, 2012 11:05 pm

Re: Filtering outputs on print commands? How?

Thu Aug 21, 2014 9:44 pm

Find works in the same way as print but it does not print anything and just returns IDs. It is mainly used in scripts. If you want to see results of find you have to type:
/ip route> :put [find static=yes]
*30000003
Then you can use this ID to get item's properties:
/ip route> :put [get [find static=yes] dst-address ]]
0.0.0.0/0
Another example:
/ip route>  :foreach Id in=[find dynamic=yes ] do={:put [get $Id gateway-status  ] }   
15.14.19.15 reachable via  pppoe-out1
bridge-local reachable
pppoe-out1 reachable
Have fun! :)

Who is online

Users browsing this forum: MSN [Bot] and 119 guests