Community discussions

MikroTik App
 
User avatar
junbr0
just joined
Topic Author
Posts: 16
Joined: Sat Jan 09, 2021 10:50 am

put members of /interface member list into variable array [SOLVED]

Sat Aug 31, 2024 5:48 pm

howdy skillfully mt people,

problem:
Parse out --> /interface list member of list "IL_wanif" into array variable will result with empty variable.

IL_wanif members -> wlan0 and inactive lte1-4 ( let say lte1,lte2,lte3,lte4)
:local ilm {:toarray [/interface list member print as-value where list=IL_wanif]};put $ilm   

result with:
.id=*55;comment=;interface=eth0_wlan0;list=IL_wanif;.id=*5d;comment=;interface=eth0_lte3;list=IL_wanif;.id=*61;comment=;interface=eth0_lte10;list=IL_wanif;.id=
*62;comment=;interface=eth0_lte0;list=IL_wanif;.id=*65;comment=;interface=eth0_lte2;list=IL_wanif;.id=*66;comment=;interface=eth0_lte1;list=IL_wanif

looks almost correct. then little more specific with ($ilm ->"interface")

:local ilm {:toarray [/interface list member print as-value where list=IL_wanif]->"interface"};put $ilm
or
:global ilm {:toarray [/interface list member print as-value where list=IL_wanif]};put ($ilm->"interface");    
result:
<empty>

expected result list of interfaces array

this will populate and giving result list of interfaces
:foreach interface in=[/interface list member print as-value where list=IL_wanif] do={:put ($interface->"interface")}
result:
eth0_wlan0
eth0_lte3
eth0_lte10
eth0_lte0
eth0_lte2
eth0_lte1
this command will fail to store result into array:
:foreach interface in=[/interface list member print as-value where list=IL_wanif] do={:global ilm [:toarray ($interface->"interface")]}
it only store 1 to variable the last interface let say "eth0_lte1"

any help would be appreciated..


regards,
Last edited by junbr0 on Wed Sep 04, 2024 2:36 pm, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: put members of /interface member list into variable array

Mon Sep 02, 2024 12:04 pm

It's all full of errors, obviously it doesn't work.

Where did you read this 5h1t?
[...]:local ilm {:toarray [/int[...]


if you overwrite the variable every time (recreating it) it is obvious that it always contains only the last entry.
You really lack the ABC of programming, regardless of whether it is RouterOS or anything else...
[...] _wanif] do={:global ilm [:toarray ($int [...]


{
:local iflist [:toarray ""]
/interface list member
:foreach ifc in=[find where list="IL_wanif"] do={:set iflist ($iflist , [get $ifc interface])}
:put [:typeof $iflist]
:put $iflist
:put ($iflist->0)
:put ($iflist->1)
}
 
User avatar
junbr0
just joined
Topic Author
Posts: 16
Joined: Sat Jan 09, 2021 10:50 am

Re: put members of /interface member list into variable array

Mon Sep 02, 2024 3:34 pm

yes still newbie scriptor..trial by errors...
wrong logic yes...
let me learn your working code after im back from hospital ..

regards
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12445
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: put members of /interface member list into variable array

Mon Sep 02, 2024 6:20 pm

im back from hospital ..

:? I hope nothing serious...
 
User avatar
junbr0
just joined
Topic Author
Posts: 16
Joined: Sat Jan 09, 2021 10:50 am

Re: put members of /interface member list into variable array

Tue Sep 03, 2024 11:19 am

im back from hospital ..
:? I hope nothing serious...
yea hopefully everything just fine :)

anyway it works ! thank you.
rextended code for gathering interfaces into array
this could be hint to newbies seeking for answer :)
:global iflist [:toarray ""]
/interface list member
:foreach ifc in=[find where list="IL_wanif"] 	do={:set iflist ($iflist , [get $ifc interface])}

than trying to parse interfaces into array using syntax "print as-value where list="

regards,

Who is online

Users browsing this forum: Google [Bot] and 3 guests