tx-bytes rx-bytes have spaces and are unusable. Please help (edited and added more info)
Posted: Sun Jun 11, 2017 5:31 pm
Hello everyone,
I'm transforming a scipt from one of the users on this forum (viewtopic.php?t=87565#) to be compatible with the newest version.
I use RouterOS v6.38.5 on Winbox v3.11 on hEX Routerboard.
Therefore I'm trying to use tx-bytes and rx-bytes but I get a value with spaces back from routerOS. I cannot use this value, when I want to add them, I get
41 045 997;41 045 997
This is the code that I want to use;
my output is:
I tried to debug the following;
'tonum' doesn't change
I made a script to delete spaces, however, the script cannot find any spaces in the integers $counterrx and $countertx
Also it shows me that the length of the number is 1 ???
I used this script;
output is:
output:
I tried to find spaces and remove them with this code;
but that also doesn't work. posspace is empty and counterrx2 doesn't change at all. I also tried to find , but same behavior.
I found out that the value is actually correct (when I verify stats in the interface list in Winbox)
Can someone please help me?
Thank you very much,
Maikel
Edit: I edited almost the whole post to make it much more clear, hopes it helps understanding the situation and to let you see I tried. Also I would like to say that I use RouterOS programming language (C?) for four hours now
I'm transforming a scipt from one of the users on this forum (viewtopic.php?t=87565#) to be compatible with the newest version.
I use RouterOS v6.38.5 on Winbox v3.11 on hEX Routerboard.
Therefore I'm trying to use tx-bytes and rx-bytes but I get a value with spaces back from routerOS. I cannot use this value, when I want to add them, I get
41 045 997;41 045 997
This is the code that I want to use;
Code: Select all
:local counterrx [/interface ethernet get eth2-master rx-bytes]
:put "counterrx:"
:put $counterrx
:local countertx [/interface ethernet get eth2-master tx-bytes]
:put "countertx:"
:put $countertx
:tonum $counterrx
:tonum $countertx
set $counter ( $counterrx + $countertx )
:put "counter:"
:put $counter
I would expect to get numbers (integer) like 41278785 (without spaces) and 391157213 for rx-bytes ($counterrx) and tx-bytes ($countertx)counterrx:
41 278 785
countertx:
391 157 213
counter:
41 278 785;391 157 213
I tried to debug the following;
'tonum' doesn't change
I made a script to delete spaces, however, the script cannot find any spaces in the integers $counterrx and $countertx
Also it shows me that the length of the number is 1 ???
I used this script;
Code: Select all
:local counterrx [/interface ethernet get eth2-master rx-bytes]
:put "counterrx:"
:put $counterrx
:local Replacechar do={
:for i from=0 to=([:len $1] - 1) do={
:local char [:pick $1 $i]
:if ($char = $2) do={
:set $char $3
}
:set $output ($output . $char)
}
:return $output
}
:local counterrx2 [ $Replacechar $counterrx " " "" ]
:put $counterrx2
:put "counterrx length:"
:put [ len $counterrx ]
:local blub "blubblub"
:put "blubblub length:"
:put [ len $blub ]
As last thing I checked if the number $counterrx is an array and counted the elements;counterrx:
41 946 248
41 946 248
counterrx length:
1
blubblub length:
8
Code: Select all
:local counterrx [/interface ethernet get eth2-master rx-bytes]
:foreach nr,xxx in={$counterrx} do={
:put ("$nr=$xxx")
};
Only the first number gets counted?0=42 147 960
I tried to find spaces and remove them with this code;
Code: Select all
:local posspace [ :find $counterrx " " -1]
:put $posspace
:local counterrx2 [:pick $counterrx 0 $posspace]
:put $counterrx2
I found out that the value is actually correct (when I verify stats in the interface list in Winbox)
Can someone please help me?
Thank you very much,
Maikel
Edit: I edited almost the whole post to make it much more clear, hopes it helps understanding the situation and to let you see I tried. Also I would like to say that I use RouterOS programming language (C?) for four hours now