# Add a Data Limit To Trial Hotspot Users - MikroTik Script RouterOS

    The following script allows you to assign a data limit to trial hotspot users and

    a) have them kicked offline upon reaching this limit
    b) create a temporary local user to stop them from logging back in again
    This is a feature which is not available via the current hotspot settings, so I decided to script it into existence. Enjoy!

    Script to check users for those over the limit:
    Make a scheduler entry to run this every X minutes, I'd recommend every 5-10 minutes.

    #Download limit in MB
    :local downquotamb "50"
    # Do not modify anything below this line #
    :local downquota [$downquotamb * 1000]
    :local counter
    :local datadown
    :local username
    :local macaddress
    :foreach counter in=[/ip hotspot active find ] do={
    :set datadown [/ip hotspot active get $counter bytes-out]
    :if ($datadown>$downquota) do={
    :set username [/ip hotspot active get $counter user]
    :set macaddress [/ip hotspot active get $counter mac-address]
    /ip hotspot user remove [/ip hotspot user find where name=$username]
    /ip hotspot user add name=$username limit-bytes-out=$downquota mac-address=$macaddress
    /ip hotspot active remove $counter
    :log info "Logged out $username - Reached download quota"
    }}
    Script to clear all manually created user accounts; this can be done hourly, daily or weekly depending on your requirements.

    :foreach counter in=[/ip hotspot user find ] do={/ip hotspot user remove \$counter}
    Notes:
    You can modify how often you want each of the script

    Credit: https://wiki.mikrotik.com/wiki/Add_a_data_limit_to_trial_hotspot_users