It doesn’t seem like a difficult task at all, but I can’t cope:
:put [/port find name=usb2]
*1
:put [/port find name=usb2 !inactive]
*1
:put [/port find name=usb2 !inactive !used-by]
… nothing
:put [/port find name=usb2 !inactive used-by]
… nothing too !
:put [/port find !used-by]
… nothing !
:put [:typeof [/port find used-by]]
array
What’s the matter ? The “used-by” property is not read into the console? Something wrong with ROS or am I doing something wrong?
Tried it on ROS 6.46 - 6.48…
I will formulate the task once again (maybe I did not explain it clearly): How do I, when searching in :foreach, or just conditionally select only those ports from / port that are not used by anyone (free)?
Or can’t this be done for the used-by property? There must be a solution…
After all, router ports cannot have the same names (ROS does not make them the same itself and does not allow the user to set the same names to ports)
First, use right syntax
Second, the “find” results are ids, not field value.
I do not have usb2, only serial0:
:put [/port find where name=serial0]
*1
ok, *1 is the id of the serial0
:put [/port find name=serial0 !inactive !used-by]
(<- nothing here…)
nothing as expected, the serial0 is used by “Serial Console” (and is active)
:put [:typeof [/port find name=serial0 !inactive !used-by]]
array
as expected, is one empty array (of IDs)
after the previous examples I disable console on serial0 and…
:put [/port find name=serial0 used-by]
(<- nothing here…)
nothing (empty array) as expected, because !used-by is “when used-by not exist” and this probably never happen since used-by is always valorized…
not-used-by-something is used-by=“”
used-by-something is used-by!=“”
What you really want is
/port print where used-by=""
:put [/port find where used-by=""]
You need to go through all the ports available on the router and select all of them that have the usb or serial type and only those that are active (!inactive) and only those that are not used by any devices (!used-by)…
Of course, I understand that the port can be occupied and freed, for example, by the console… My usb port is currently occupied by the modem, and serial0 is disconnected from the console, but …
:put [/port find name~"" !inactive !used-by]
output:
I don 't understand why… Maybe the OS router does not release the console port without rebooting? It doesn’t seem to be the case, because in /port print the ports are displayed correctly (usb is busy, serial0 is free from the console …)
I tried it on different versions, the effect is the same on different platforms with different number of ports and their occupancy…
Rex, I always read what you write! I try to read carefully, but I don’t always understand because of my poor English and the quality of the auto-translation into Russian (I already talked about this earlier). Please make allowances for my profession too (you know it) and the way patients pull me at work… Microtik is my hobby and I have to do it in very short periods of time… Everything suffers from this …
Please understand and don 't be offended …
The Router OS parser does not skip the construction:
:put [/port find name~"" inactive=no used-by=no]
apparently, the inactive parameter is readable and writable, and used-by exists only for reading (based on the Mikrotik Wiki /port)
used-by=no
can’t write (“no” it is not highlighted in green in the terminal !)
Thank you very much, dear friends of Rex & Amm0! If you’ll excuse me, I (who in the scripts is up to both of you like the moon) That’s what they call you.
Rex, thank you. Please explain for me (so that I understand for the future)- why do you still need where? What does it do, if it works correctly without it?
Is the where parameter somehow involved in filtering, or can it actually be omitted?