Community discussions

MikroTik App
 
ahmedalmosowe
just joined
Topic Author
Posts: 4
Joined: Thu Mar 03, 2016 8:06 pm

script to remove hotspot user how reached total bytes limit

Thu Mar 03, 2016 8:11 pm

script
:foreach tmpI in=[/ip hotspot user find where (limit-bytes-total > 0)] do={
:local tmpName value=[/ip hotspot user get $tmpI value-name=name];
:local tmpLimitTotal value=[/ip hotspot user get $tmpI value-name=limit-bytes-total];
:local tmpIn value=[/ip hotspot user get $tmpI value-name=bytes-in];
:local tmpOut value=[/ip hotspot user get $tmpI value-name=bytes-out];
:local tmpRemaining value=($tmpLimitTotal - ($tmpIn + $tmpOut));
:local tmpMessage value=("User: ".$tmpName.", Limit Total: ".$tmpLimitTotal.", Used In: ".$tmpIn.", Used Out: ".$tmpOut.", Remaining Total:".$tmpRemaining);
:if ([/ip hotspot user get $tmpI value-name=disabled]) do={:set tmpMessage value=("USER DISABLED: ".$tmpMessage);};
:if ($tmpRemaining < 1) do={:set tmpMessage value=("USER OUT OF BYTES: ".$tmpMessage);};
:log info message=$tmpMessage;
ip hotspot user remove [/ip hotspot user find name=$tmpName]  
}
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: script to remove hotspot user how reached total bytes limit

Thu Mar 03, 2016 8:29 pm

Does this work? It looks like it would remove all users, not just the over-budget ones.

If it's removing all users, then try this:
:foreach tmpI in=[/ip hotspot user find where (limit-bytes-total > 0)] do={
:local tmpName value=[/ip hotspot user get $tmpI value-name=name];
:local tmpLimitTotal value=[/ip hotspot user get $tmpI value-name=limit-bytes-total];
:local tmpIn value=[/ip hotspot user get $tmpI value-name=bytes-in];
:local tmpOut value=[/ip hotspot user get $tmpI value-name=bytes-out];
:local tmpRemaining value=($tmpLimitTotal - ($tmpIn + $tmpOut));
:local tmpMessage value=("User: ".$tmpName.", Limit Total: ".$tmpLimitTotal.", Used In: ".$tmpIn.", Used Out: ".$tmpOut.", Remaining Total:".$tmpRemaining);
:if ([/ip hotspot user get $tmpI value-name=disabled]) do={:set tmpMessage value=("USER DISABLED: ".$tmpMessage);};
:if ($tmpRemaining < 1) do={
  :set tmpMessage value=("USER OUT OF BYTES: ".$tmpMessage);
  ip hotspot user remove $tmpI;
};
:log info message=$tmpMessage;
}
 
ahmedalmosowe
just joined
Topic Author
Posts: 4
Joined: Thu Mar 03, 2016 8:06 pm

Re: script to remove hotspot user how reached total bytes limit

Fri Mar 04, 2016 9:40 am

Does this work? It looks like it would remove all users, not just the over-budget ones.

If it's removing all users, then try this:
:foreach tmpI in=[/ip hotspot user find where (limit-bytes-total > 0)] do={
:local tmpName value=[/ip hotspot user get $tmpI value-name=name];
:local tmpLimitTotal value=[/ip hotspot user get $tmpI value-name=limit-bytes-total];
:local tmpIn value=[/ip hotspot user get $tmpI value-name=bytes-in];
:local tmpOut value=[/ip hotspot user get $tmpI value-name=bytes-out];
:local tmpRemaining value=($tmpLimitTotal - ($tmpIn + $tmpOut));
:local tmpMessage value=("User: ".$tmpName.", Limit Total: ".$tmpLimitTotal.", Used In: ".$tmpIn.", Used Out: ".$tmpOut.", Remaining Total:".$tmpRemaining);
:if ([/ip hotspot user get $tmpI value-name=disabled]) do={:set tmpMessage value=("USER DISABLED: ".$tmpMessage);};
:if ($tmpRemaining < 1) do={
  :set tmpMessage value=("USER OUT OF BYTES: ".$tmpMessage);
  ip hotspot user remove $tmpI;
};
:log info message=$tmpMessage;
}
scrpit is worked and remove only limit bytes total
thanks
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: script to remove hotspot user how reached total bytes limit

Thu Mar 10, 2016 6:08 am

or simply add this in the hotspot user profile
script on log-out
{
:if ($cause="traffic limit reached") do={
/ip hotspot user remove [find name="$user"]
}
much simpler !!
 
ahmedalmosowe
just joined
Topic Author
Posts: 4
Joined: Thu Mar 03, 2016 8:06 pm

Re: script to remove hotspot user how reached total bytes limit

Sun Apr 17, 2016 11:40 pm

or simply add this in the hotspot user profile
script on log-out
{
:if ($cause="traffic limit reached") do={
/ip hotspot user remove [find name="$user"]
}
much simpler !!
thanks
 
User avatar
ahmedalmi
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Sat Sep 13, 2014 5:52 pm
Location: sana'a yemen
Contact:

Re: script to remove hotspot user how reached total bytes limit

Sat Apr 29, 2017 2:23 pm

just use this rule:
/ip hotspot user remove [find limit-bytes-total=($"bytes-in" + $"bytes-out")];
 
Matellito
just joined
Posts: 4
Joined: Fri Sep 14, 2012 5:02 am

Re: script to remove hotspot user how reached total bytes limit

Tue Dec 26, 2017 11:40 pm

I have a hotspot but I have problems with the XX user.
I have created a XX user and in the limit uptime I have 30 minutes, and in a shared user I have 25, everything works fine during the 30 minutes, any user can connect, but it complies with the 30 minutes of the limit uptime and no longer connects any user, only the message "USER XX HAS REACHED UPTIME LIMIT", some idea of ​​how to solve this problem, the idea is that if the XX user has already run out of time and no longer connect, but he does not use yet I can do it.

Image

Who is online

Users browsing this forum: No registered users and 11 guests