script to remove hotspot user how reached total bytes limit

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]  
}

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;
}

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

just use this rule:
/ip hotspot user remove [find limit-bytes-total=($“bytes-in” + $“bytes-out”)];

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.