Community discussions

MikroTik App
 
User avatar
senseivita
newbie
Topic Author
Posts: 35
Joined: Fri Jan 01, 2021 4:20 am

How do I list items in the CLI entry?

Mon Aug 07, 2023 8:25 am

Sometimes you need to pick several items from a list or enter several items and to apply them to an entry, or both. i.e; 1:many, many:1, many:many; e.g;

We'd like to set the winbox service available on VRF red, green, and blue;
/ip/service/set winbox vrf= ?

I tried:
/ip/service/set winbox vrf=R,G,B
/ip/service/set winbox vrf=R;G;B
/ip/service/set winbox vrf="R G B"
/ip/service/set winbox vrf="R,G,B"
/ip/service/set winbox vrf="R;G;B"
/ip/service/set winbox vrf={R,G,B}
/ip/service/set winbox vrf={R;G;B}
/ip/service/set winbox vrf={R;G;B;}
/ip/service/set winbox vrf={R G B}
/ip/service/set winbox vrf=(R,G,B)
/ip/service/set winbox vrf=(R;G;B)
/ip/service/set winbox vrf=(R;G;B;)
/ip/service/set winbox vrf=(R G B)
(Obviously, none worked.)
Now, if I were setting a the same parameters to several items, for instance, still using services as an example:
[user@impossiblecli] /ip/service> print
Flags: X, I - INVALID
Columns: NAME, PORT, ADDRESS, CERTIFICATE, VRF
#   NAME     PORT  ADDRESS    CERTIFICATE     VRF
0 X telnet     23                             main
1 X ftp        21
2   www        80                             main
3   ssh        22  0.0.0.0/0                  main
4   www-ssl   443             premlinkv50rsa  main
5 X api      8728                             main
6   winbox   8291                             main
7   api-ssl  8729             premlinkv50rsa  main
I could use "number=" to target them directly, which I believe does allow using commas to list them, but it is tedious if the list is large. Another option is if I remember correctly an in-line search function, but that's not as precise as mixing ranges and individual entries in the line e.g; "number=1-12,15,16,20-26,28", not to mention mastering of the required more syntax. I assume this is possible but I cannot find documentation about it or I'm just too dumb to interpret it, furthermore, in the old wiki there used to be a connection with winbox's menu system, allegedly the same as the CLI, so one could kind of loosely put things together from that, but the new wiki seems structured topic-basic; it's harder to pinpoint a winbox menu that (loosely) translates to the CLI and go from there.

There are multi-valued items about everywhere in winbox, but these are listed in their own little box so there's no string that could be copied to the CLI. I've found no reference about how to list things in-line in the CLI yet, but I'm still hopeful one must have be given somewhere.

Thanks.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3509
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: How do I list items in the CLI entry?

Mon Aug 07, 2023 9:00 am

It's not your syntax re the VRF...
AFAIK, "/ip service winbox vrf=" only allows one VRF to be applied.

If you just want to print a subset there is a "where" clause, so can use "/ip service print where vrf=main"

"find" is the operator to go through a list programmatically. You don't need to use numbers=. The "find" returns the ".id" field for an item in the list, and the :foreach will go through all the items one at a time, using a variable "$item". Since find just returns an ".id", we need to use a "get" operator to fetch all the fields for the particular entry (reference by an .id in the $item).
:foreach item in=[/ip service find vrf=main] do={
    :put [/ip service get $item]
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How do I list items in the CLI entry?

Mon Aug 07, 2023 10:16 am

I tried:

Instead of randomly trying things that don't exist, first set via winbox as you would like it to be... If you see that it won't let you put more than one, guess why...
Then when you're satisfied, you make a nice export of that section to see how it's configured and then what the syntax is like to reconfigure it the same elsewhere...

Also, on CLI, press <TAB> for see possible options and <F1> for the possible values, etc....
 
pe1chl
Forum Guru
Forum Guru
Posts: 10248
Joined: Mon Jun 08, 2015 12:09 pm

Re: How do I list items in the CLI entry?

Mon Aug 07, 2023 11:52 am

Yes, this is a serious problem with VRF, one of the reasons I do not use it.
Router-side services are always active on only ONE of the configured VRFs.
This is usually not what you want. E.g. NTP service should work on all VRFs.
 
User avatar
senseivita
newbie
Topic Author
Posts: 35
Joined: Fri Jan 01, 2021 4:20 am

Re: How do I list items in the CLI entry?

Mon Sep 11, 2023 3:57 pm

Sorry, for the hold up.

Yeah, I know the VRF thing was a bad example. I think it did convey the message though :)

I know about inline scripts, but that's what I'm trying to avoid. I was/am hoping for something like a glob expression. Also, I've exported data entered on winbox before, it's useful but doesn't teach much since the CLI for basic operations, such as the ones used in the exported file, is easy, the file would only help if I'm looking to do is add new data to the system, for modifications not so much.

This is another, valid--I checked, example:

Say, I added IP ranges as address lists to work with them in the firewall later, but carelessly I added them almost all of them to the same list (number 13 is the odd one):
/ipv6/firewall/address-list> print
Columns: LIST, ADDRESS
 # LIST   ADDRESS
 0 z0100  2001:db8:100::/64
 1 z0100  2001:db8:200::/64
 2 z0100  2001:db8:300::/64
 3 z0100  2001:db8:400::/64
 4 z0100  2001:db8:500::/64
 5 z0100  2001:db8:600::/64
 6 z0100  2001:db8:700::/64
 7 z0100  2001:db8:800::/64
 8 z0100  2001:db8:900::/64
 9 z0100  2001:db8:a00::/64
10 z0100  2001:db8:b00::/64
11 z0100  2001:db8:c00::/64
12 z0100  2001:db8:d00::/64
13 z0e00  2001:db8:e00::/64
14 z0100  2001:db8:f00::/64
15 z0100  2001:db8:1000::/64
16 z0100  2001:db8:1100::/64
17 z0100  2001:db8:1200::/64
18 z0100  2001:db8:1300::/64
19 z0100  2001:db8:1400::/64
20 z0100  2001:db8:1500::/64
21 z0100  2001:db8:1600::/64
22 z0100  2001:db8:be00::/64
23 z0100  2001:db8:bf00::/64
24 z0100  2001:db8:c000::/64
I need now to remove all entries on the list to add the corrected lists. But…
[---] /ipv6/firewall/address-list>
add         disable     enable     find      remove     set
comment     edit        export     print     reset
[---] /ipv6/firewall/address-list> remove numbers=0-12
expected end of command (line 1 column 17)
[---] /ipv6/firewall/address-list> remove numbers=0:12
expected end of command (line 1 column 17)
[---] /ipv6/firewall/address-list> remove numbers=*
syntax error (line 1 column 16)
Tab-completion works with items only within the file structure, with minimal exceptions. I guess, but even "quit" can only be invoked from "/".
 
User avatar
spippan
Member
Member
Posts: 334
Joined: Wed Nov 12, 2014 1:00 pm
Location: Austria

Re: How do I list items in the CLI entry?

Mon Sep 11, 2023 4:29 pm

Sometimes you need to pick several items from a list or enter several items and to apply them to an entry, or both. i.e; 1:many, many:1, many:many; e.g;

We'd like to set the winbox service available on VRF red, green, and blue;
/ip/service/set winbox vrf= ?

I tried:
/ip/service/set winbox vrf=R,G,B
/ip/service/set winbox vrf=R;G;B
/ip/service/set winbox vrf="R G B"
/ip/service/set winbox vrf="R,G,B"
/ip/service/set winbox vrf="R;G;B"
/ip/service/set winbox vrf={R,G,B}
/ip/service/set winbox vrf={R;G;B}
/ip/service/set winbox vrf={R;G;B;}
/ip/service/set winbox vrf={R G B}
/ip/service/set winbox vrf=(R,G,B)
/ip/service/set winbox vrf=(R;G;B)
/ip/service/set winbox vrf=(R;G;B;)
/ip/service/set winbox vrf=(R G B)
(Obviously, none worked.)
Now, if I were setting a the same parameters to several items, for instance, still using services as an example:

There are multi-valued items about everywhere in winbox, but these are listed in their own little box so there's no string that could be copied to the CLI. I've found no reference about how to list things in-line in the CLI yet, but I'm still hopeful one must have be given somewhere.

Thanks.
first, the "/ip services" still only can be active in ONE VRF at a time.
but as you said, maybe not the best example

second:
if you need to set/change a value of several items maybe look into the "find" parameter
it works quite the same as the "where" argument in "print where ..."
e.g. you could use it like
/ip/firewall/address-list set [find where list="LISTNAME-A"] list="LISTNAME-B
instead of "=" you could use "~" to get partial matches (regex)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How do I list items in the CLI entry?

Tue Sep 12, 2023 3:24 am

[---] /ipv6/firewall/address-list>
add         disable     enable     find      remove     set
comment     edit        export     print     reset
[---] /ipv6/firewall/address-list> remove numbers=0-12
expected end of command (line 1 column 17)
[---] /ipv6/firewall/address-list> remove numbers=0:12
expected end of command (line 1 column 17)
[---] /ipv6/firewall/address-list> remove numbers=*
syntax error (line 1 column 16)
Let's clarify one thing straight away, definitively: using numbers= (or only numbers) on scripts is fullshift.
remove 0,1,2,3,4,5,6,7,8,9,10,11,12
or use for x from=0 to=12 step=1 do={remove $x}....

Who is online

Users browsing this forum: Nullcaller and 6 guests