Community discussions

MikroTik App
 
nik545
just joined
Topic Author
Posts: 2
Joined: Thu Feb 25, 2021 7:00 pm

what i do wrong

Thu Feb 25, 2021 7:10 pm

hi, im trying simple script but cant get it working

:local txbyte 
:set txbyte [ /interface ethernet get value-name=driver-tx-byte ether1]
:if ($txbyte > 50000) do = 
 {
/interface ethernet reset-counters ether1
	}
Script Error: cannot compare if nothing is more than time interval
i checked varible by :put $txbyte the :set is working fine problem in IF statement, so can anyone plz tell me what i did wrong?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: what i do wrong  [SOLVED]

Fri Feb 26, 2021 1:38 pm

Some investigation shows that the output of your command do have spaces.

"1234" bytes shows as "1 234"
viewtopic.php?t=122489

I have cleaned up the script in that thread some. Cut and past this to command line. (to create a function)
:global removeSpace do={
	:local temp
	:for i from=0 to=([:len $t] - 1) do={
		:local char [:pick $t $i]
		:if ($char = " ") do={
			:set $char ""
		}
		:set temp ($temp . $char)
	}
	:return $temp
}

Then change your script to some like this:
:local txbyte 
:set txbyte [$removeSpace t=[:tostr [/interface ethernet get ether1 value-name=driver-rx-byte ]]]
:if ($txbyte > 50000) do={
	/interface ethernet reset-counters ether1
}
 
nik545
just joined
Topic Author
Posts: 2
Joined: Thu Feb 25, 2021 7:00 pm

Re: what i do wrong

Fri Feb 26, 2021 7:55 pm

thanks for your help, but i did not get your code runing, i fix it by
:local removeSpace do={ :local temp;
    :for i from=0 to=([:len $t] - 1) do={ :local char [:pick $t $i];
        :if ($char = " ") do={ :set $char ""; }
        :set temp ($temp . $char); }
    :return $temp; }

:put [$removeSpace t=[:tostr [/interface ethernet get value-name=driver-tx-byte ether1]]]

:local txbyte 
:set txbyte [$removeSpace t=[:tostr [/interface ethernet get value-name=driver-tx-byte ether1]]]

:if ($txbyte > 50000) do={
	/interface ethernet reset-counters ether1
:put [/interface ethernet get value-name=driver-tx-byte ether1] 
}
works like charm , ty

Who is online

Users browsing this forum: No registered users and 25 guests