You can if you name your queues with a first character that is a digit, otherwise you would have to do :find of a collation string. There’s no function that returns the raw byte value of an arbitrary element.
Just give us a bash
Replace or remove character(s) in a string.
{
global replaceCharacterFunc do={
while condition=[find $1 $2 0] do={
set $1 ("$[pick $1 0 ([find $1 $2]) ]".$3."$[pick $1 ([find $1 $2]+1) ([len $1])]")}
return $1
}
# Replace a character with an other character
put [$replaceCharacterFunc "Can-t-be-used-as-name-for-variable" "-" "*"]
# Remove unwanted character(s)
put [$replaceCharacterFunc "Can-t-be-used-as-name-for-variable" "-"]
}
Correct that the first character in the string could also be the one that could be replaced:
while condition=[find $1 $2 0] do={
Update: added matching on multiple chars and replace those with one or more chars.
{
global mreplaceCharFunc do={
:local n [:len $2]
while condition=[find $1 $2 0] do={
set $1 ("$[pick $1 0 ([find $1 $2]) ]".$3."$[pick $1 ([find $1 $2]+$n) ([len $1])]")}
return $1
}
}
:set $a [$mreplaceCharFunc "this @@@ @@ @ test of replacing multiple char(s)" @@ is]; :put $a
this is@ is @ test of replacing multiple char(s)
Abilities with script to scan scan and connect into SSID with best signal when SSID start with criteria example:
This is a very important facility for field installations because the technician will not need to link or the notebook will be expedited or serviced, as is the case with GPON (expedited installation). example:
/interface wireless set [find default-name=wlan1] scan-and-connect = based-best-signal-ssid = [find=IspXSectorY];
Ability of AP to announce for all stations that there will be a nv2-mixed-background-scan-from-all of freq-usage from all stations and AP, review graphic for AP and mix as scan of all based at a time ex: 04:00am and temporarily save the RAM into the AP,
of the month that had to stop or painel for some seconds, we would assimilate a scan more from all clients and that would work even for AC chips Also,
when someone request a scan from or AP, warn them that they have scan and show a graph. example:
/interface wireless set [find default-name=wlan1] set nv2-mixed-background-scan-from-all=enabled nv2-mixed-background-scan-time = 04: 00am
I prefer scsh.
Need.
Lua script.
To me the singularly most important addition would be opening this up to the community so that they could create and share functions safely and easily. So that you can leverage all the developers to contribute to a user extensible library.
You can always start such a project or join an existing one, e.g. on github.
Don’t expect this from MikroTik, they are not an open-source company!
Just as said above, i think you have more chances with it on github
[quote=MtHoodlum post_id=816704 time=1599927658 user_id=55480]
A built-in function that broke up files and variables into 4096 byte chunks would be extremely useful.
[/quote]
I think the scripting language should be extended with a file open/read/write/close construct where you can open a file (a handle is returned), then read or write it in a loop either line-by-line or as fixed-size blocks (up to 4096 bytes), and then close it when finished. The total size of the file would be arbitrary (as long as it fits on the storage).
This would be similar to the C functions fopen, fgets, fputs, fread, fwrite, fclose.
This would allow reading and processing long lists of data like blacklists etc.
Even kind of “:foreach line in=[/file xxx get-lines] do={$process $line}” should be enough, I believe…
Ok, that would likely read the entire fire beforehand and store it into an array in memory, but indeed for many purposes (and with today’s typical RAM size) that would already be very good!
Of course it would be nice when there also was some way to write-out such an array to a file (1 array element per line, total array larger than 4K).
What if you use multiple array’s in the foreach? Till now I read/stores up to 64KB files using one array.
When one array is full then switch to the next one.
Oh, I did not know that there was a 64kB limit on arrays.
When that is the case, forget about that method and just do the open/read/write/close. It has no such limits, it can loop to read all lines and process them without storage limit issues.
(reading and processing lines one by one does not necessarily mean they have to be permanently stored somewhere in memory, maybe it is just to add them to an address list or similar purposes)
This I am using to read up to 64KB from a file. Sadly always the first up to 64KB from a file.
:local result [/tool fetch url=$url as-value output=user]; :if ($result->"downloaded" < 64) do={ :local data ($result->"data")
If a file is bigger then that, then the result is not transferred to the array due to the data is incomplete. This could work also for bigger files if the webserver supports resume and Mikrotik implements a new starting point for downloading the file using the resume option.
Quick-and-dirty:
Resume available: current read data is different from the previous data
No resume available: current read data is the same as the previous data
Edit: changed the check on the size of the downloaded file: :if ($result->“downloaded” < 64)
Does that already split the data on line boundaries into elements of the array? In that case it is equivalent to what Chupaka suggested to be added.
However, I prefer solutions that do not have such small arbitrary limits.
E.g. when I would like to download a file with lines with addresses or subnets, to add them to an address list, I would like to be able to process a file no matter if it is 10K 100K or 1M.
The open/read/close method does not have any inherent size limits, you can read the lines one by one in a loop, parse them to extract the interesting data, check if the item already is in the address list, if not, add it, and loop until all lines are read.
No need to fiddle with “if larger than this then that”.
(I also use the loading of address lists via DNS but it has silly limits as well, you cannot load like 10000 items this way. and it also does not support subnets)
I remember they promised a possibility to use routing filters to add/fetch routes to/from address lists in v7. That would probably be better solution for this case…
For this to be of any use, first two changes have to be made:
- address list from DNS should allow subnets, via a TXT record containing CIDR subnet notation (in addition to current A and AAAA record support)
- address list from DNS should have no unreasonable size limits, i.e. when I can “dig” the DNS name from a Linux shell, it should also be able to load that into an address list.
e.g.: dig -t A (some domain name) | wc -l
3546
cannot currently load this into an address list…
Oh, I forgot to mention BGP… I mean, with that routing filter one may distribute address list (with subnets and whistles) via BGP, not using files…
Ok, I thought you meant to use address lists as part of routing filters (the other way around) and then distribute those lists via DNS…