Community discussions

MikroTik App
 
prince1990love
newbie
Topic Author
Posts: 32
Joined: Thu Oct 15, 2015 7:19 pm

question for professional!!

Tue Mar 01, 2016 8:07 pm

i want script for auto delete users after reaching traffic limit in hotspot!
and that is my code

:foreach i in [/ip hotspot user find profile=default] do={
:if ([/ip hotspot user get $i limit-bytes-total]<=[/ip hotspot user get $i \
limit-bytes-total]) do={
/ip hotspot user remove $i
}
}

but it's not work
what is wrong ????
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: question for professional!!

Tue Mar 01, 2016 9:28 pm

your script logic is flawed....
:if ([/ip hotspot user get $i limit-bytes-total]<=[/ip hotspot user get $i limit-bytes-total]) do={ 
  /ip hotspot user remove $i 
}
it basically says if X <= X then remove.... it might as well say "if 1 = 1 then remove" or - just "remove"

You're pulling the same field from the same user (held in $i) twice, and comparing them....

you need to do something more like this:
/ip hotspot user
:local bytestotal = [ :get $i bytes-in ] + [ :get $i bytes-out ]
:if ( $bytestotal > [ :get $i limit-bytes-total ] ) do={
  /ip hotspot user remove $i
}
My syntax for the addition between the two gets might be wrong, but the logic is what's important. You need to get the current used bytes and compare that with the limit-bytes-total value, which is just a limit set by the account's properties and never changes.
 
prince1990love
newbie
Topic Author
Posts: 32
Joined: Thu Oct 15, 2015 7:19 pm

Re: question for professional!!

Tue Mar 01, 2016 11:28 pm

thank you ZeroByte for reply but is not work :( any idead
 
prince1990love
newbie
Topic Author
Posts: 32
Joined: Thu Oct 15, 2015 7:19 pm

Re: question for professional!!

Tue Mar 01, 2016 11:38 pm

please give me a complete script if possible zeroByte
 
prince1990love
newbie
Topic Author
Posts: 32
Joined: Thu Oct 15, 2015 7:19 pm

Re: question for professional!!

Wed Mar 02, 2016 5:05 am

any body can help me pls!!!