Community discussions

MikroTik App
 
hengst
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Sun Jan 03, 2010 3:04 pm

123abc only need 123 :pick how to

Sat Nov 25, 2017 5:10 pm

example :

:global rx-var [/interface wireless registration-table get 0 rx-rate ]

result : 123Mbps-20MHz/2S

how to get only "123" from string in Mikrotik scripting.


another thing is,

:global rx-var [/interface wireless registration-table get 0 rx-rate ]

can also be 1.2Mbps-20Mhz/2S

now i need only "1.2"


and last, maybe the easy part i need it to be usable in Simple Queue, so converted to bps.
 
User avatar
jspool
Member
Member
Posts: 469
Joined: Sun Oct 04, 2009 4:06 am
Location: Oregon

Re: 123abc only need 123 :pick how to

Sat Nov 25, 2017 9:46 pm

:local long1 123ABC
:local long2 "1.2Mbps-20Mhz/2S"

:log info "Long1 is $long1"
:log info "Long2 is $long2"

:local short1 [:pick $long1 0 3]
:log info "Short1 value is $short1"

:local short2 [:pick $long2 0 3]
:log info "Short2 value is $short2"
Log Print:
nov/26 03:41:58 script,info Long1 is 123ABC 
nov/26 03:41:58 script,info Long2 is 1.2Mbps-20Mhz/2S 
nov/26 03:41:58 script,info Short1 value is 123 
nov/26 03:41:58 script,info Short2 value is 1.2
 
hengst
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Sun Jan 03, 2010 3:04 pm

Re: 123abc only need 123 :pick how to

Sun Nov 26, 2017 3:36 pm

Yes i know the " : pick " command. but i cant use it i think .

The 123Mbps-20MHz/2S can sometimes be 1.2Mbps-20MHz/2S

i need to strip of the "Mbps-20MHz/2S" , so only 123 or 1.2

maybe it can be done with regular expressions and binary operator ~ , but there is to little info for me to understand in manual

“~” 	binary operator that matches value against POSIX extended regular expression 	Print all routes which gateway ends with 202
/ip route print where gateway~"^[0-9 \\.]*202\$"
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: 123abc only need 123 :pick how to

Tue Dec 05, 2017 7:41 am

Sure it is easy :wink:

:global RX [/interface wireless registration-table get 0 rx-rate]
:log info [:pick $RX 0 [:find $RX "M"]]

Best Regards
 
hengst
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Sun Jan 03, 2010 3:04 pm

Re: 123abc only need 123 :pick how to

Tue Dec 05, 2017 9:18 am

Sure it is easy :wink:
Thanks ADahi ! , i will have a play with it.

i want to achieve a script that will set a simple queue to the wlan.

simple queue needs to be no higher than 80% of the connection data rate.

it also has to be dynamic, so when data rate is going up, so will the queue.

maybe you want to help some more writing such a script

Who is online

Users browsing this forum: No registered users and 28 guests