# Interface Data Quota

**URL:** <https://forum.mikrotik.com/t/interface-data-quota/79514>\
**Category:** Beginner Basics\
**Created:** [July 30, 2014, 8:42am UTC](https://forum.mikrotik.com/t/interface-data-quota/79514 "2014-07-30T08:42:49Z")\
**Posts on this page:** 1\
**Showing post:** 38

<div class="post-metadata">

**Author:** ![truefriendcz](https://forum.mikrotik.com/letter_avatar/truefriendcz/32/6_449c533f586939b6e5f246632a46421f.png) [@truefriendcz](https://forum.mikrotik.com/u/truefriendcz)\
**Post date:** [January 3, 2024, 10:41am UTC](https://forum.mikrotik.com/t/interface-data-quota/79514/38 "2024-01-03T10:41:15Z")

</div>

Hello. Please how i can modify LTE script for data quota reset every midnight (daily)?  
I am running script every 1 hours and i want reset limit every day.

> [@EdPa](#):
>
> Hello
> 
> > For LTE:
> 
> ```plaintext
> # /$$ /$$$$$$$$/$$$$$$$$ /$$ /$$ /$$ /$$                        
> # | $$ | __$$__ / $$ _____/| $$ |__ / |__/ | $$                        
> # | $$ | $$ | $$ | $$ /$$ /$$$$$$/$$$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ 
> # | $$ | $$ | $$$$$ | $$ | $$| $$_ $$_ $$| $$|_ $$_/ /$$ __$$ /$$__ $$
> # | $$ | $$ | $$ __/ | $$ | $$| $$ \ $$ \ $$| $$ | $$ | $$$$$$$$| $$ \__ /
> # | $$ | $$ | $$ | $$ | $$| $$ | $$ | $$| $$ | $$ /$$| $$ _____ /| $$      
> # | $$$$$$$$| $$ | $$$$$$$$| $$$$$$$$| $$| $$ | $$ | $$| $$ | $$$$/| $$$$$$$| $$      
> # | ________/|__ / | ________/|________ /| __/|__ / | __/ |__ /| __/ \___ / \ _______/|__ /      
> #  
> # Using: Set all var in User config section. Add scripts to schedule with onstart and interval 30 sek       
> :do {              
> #######################################################################################################
> # User config
> #Set limit in MB                                                                                                                                                     
> :local limit 12288 
> #Set day to reset limit
> :local dayresetlimit 1
> #Set interface
> :local interf "lte1"
> #Set auto bring up interface 
> :local autointon true
> #######################################################################################################
> :local filename "counter.txt"
> :local filewarn "warning.txt"
> :local fileref "refcount.txt"
> :local reblock "reblock.txt"
> :local status
> :if ([:len [/file find where name=$filewarn]] < 1 ) do={
> /file print file=$filewarn where name=$filewarn
> /delay delay-time=2
> /file set $filewarn contents=$percent
> };
> :if ([:len [/file find where name=$filename]] < 1 ) do={
> /file print file=$filename where name=$filename
> /delay delay-time=2;
> /file set $filename contents=0
> }
> :if ([:len [/file find where name=$reblock]] < 1 ) do={
> /file print file=$reblock where name=$reblock
> /delay delay-time=2;
> /file set $reblock contents=1
> }
> :if ([:len [/file find where name=$fileref]] < 1 ) do={
> /file print file=$fileref where name=$fileref
> /delay delay-time=2;
> /file set $fileref contents=0
> }
> :local reblocker ([/file get $reblock contents])
> :local curdate [/system clock get date]
> :local day [:pick $curdate 4 6]
> :if ( $day = $dayresetlimit and $reblocker = 0) do={
> /file set $filename contents=0
> /file set $filewarn contents=0
> /file set $fileref contents=0
> /interface lte set $interf disabled=no
> /file set $reblock contents=1
> :log info "Limit reset, int $interf bring up" 
> /delay delay-time=5;
> :log info "Clear int counters - reboot"
> #TODO find another method for interf clear counters 
> /system reboot
> } 
> :if ( $day != $dayresetlimit ) do={
> /file set $reblock contents=0
> }
> :local before
> :local correct
> :local ref
> :local newdata
> :local tx [/interface get $interf tx-byte] 
> :local rx [/interface get $interf rx-byte] 
> :set $newdata (( $rx + $tx ) / 1024 / 1024 )
> :set $before [/file get $filename contents]
> :if ( $newdata < $before ) do={
> :set $ref [/file get $fileref contents]
> :set $correct ( $before + $newdata - $ref ) 
> /file set $fileref contents=$newdata
> /file set $filename contents=$correct
> } 
> :if ( $newdata >= $before ) do={
> /file set $filename contents=$newdata
> }
> :local traffic ([/file get $filename contents])
> :log warning "Limit: $limit MB"
> :local percent ($traffic*100 / $limit)
> :log warning "Use: $percent%"
> /file set $filewarn contents=$percent
> :if ($percent >= 100) do={
> /file set $filewarn contents=$percent
> /interface lte set $interf disabled=yes
> }
> :if ($percent < 100 and $autointon = true) do={
> :set $status [/interface get $interf value-name=disabled] 
> :if ($status = true) do={
> /interface lte set $interf disabled=no
> }
> }
> } on-error={ :log error "Error LTELimiter "};
> 
> ```
> 
> > for PPP-Client
> 
> ```plaintext
> # /$$ /$$$$$$$$/$$$$$$$$ /$$ /$$ /$$ /$$                        
> # | $$ | __$$__ / $$ _____/| $$ |__ / |__/ | $$                        
> # | $$ | $$ | $$ | $$ /$$ /$$$$$$/$$$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ 
> # | $$ | $$ | $$$$$ | $$ | $$| $$_ $$_ $$| $$|_ $$_/ /$$ __$$ /$$__ $$
> # | $$ | $$ | $$ __/ | $$ | $$| $$ \ $$ \ $$| $$ | $$ | $$$$$$$$| $$ \__ /
> # | $$ | $$ | $$ | $$ | $$| $$ | $$ | $$| $$ | $$ /$$| $$ _____ /| $$      
> # | $$$$$$$$| $$ | $$$$$$$$| $$$$$$$$| $$| $$ | $$ | $$| $$ | $$$$/| $$$$$$$| $$      
> # | ________/|__ / | ________/|________ /| __/|__ / | __/ |__ /| __/ \___ / \ _______/|__ /      
> #  
> # Using: Set all var in User config section. Add scripts to schedule with onstart and interval 30 sek       
> :do {              
> #######################################################################################################
> # User config
> #Set limit in MB                                                                                                                                                     
> :local limit 12288 
> #Set day to reset limit
> :local dayresetlimit 1
> #Set interface
> :local interf "ppp-out1"
> #Set auto bring up interface 
> :local autointon true
> #######################################################################################################
> :local filename "counter.txt"
> :local filewarn "warning.txt"
> :local fileref "refcount.txt"
> :local reblock "reblock.txt"
> :local status
> :if ([:len [/file find where name=$filewarn]] < 1 ) do={
> /file print file=$filewarn where name=$filewarn
> /delay delay-time=2
> /file set $filewarn contents=$percent
> };
> :if ([:len [/file find where name=$filename]] < 1 ) do={
> /file print file=$filename where name=$filename
> /delay delay-time=2;
> /file set $filename contents=0
> }
> :if ([:len [/file find where name=$reblock]] < 1 ) do={
> /file print file=$reblock where name=$reblock
> /delay delay-time=2;
> /file set $reblock contents=1
> }
> :if ([:len [/file find where name=$fileref]] < 1 ) do={
> /file print file=$fileref where name=$fileref
> /delay delay-time=2;
> /file set $fileref contents=0
> }
> :local reblocker ([/file get $reblock contents])
> :local curdate [/system clock get date]
> :local day [:pick $curdate 4 6]
> :if ( $day = $dayresetlimit and $reblocker = 0) do={
> /file set $filename contents=0
> /file set $filewarn contents=0
> /file set $fileref contents=0
> /interface ppp-client set $interf disabled=no
> /file set $reblock contents=1
> :log info "Limit reset, int $interf bring up" 
> /delay delay-time=5;
> :log info "Clear int counters - reboot"
> #TODO find another method for interf clear counters 
> /system reboot
> } 
> :if ( $day != $dayresetlimit ) do={
> /file set $reblock contents=0
> }
> :local before
> :local correct
> :local ref
> :local newdata
> :local tx [/interface get $interf tx-byte] 
> :local rx [/interface get $interf rx-byte] 
> :set $newdata (( $rx + $tx ) / 1024 / 1024 )
> :set $before [/file get $filename contents]
> :if ( $newdata < $before ) do={
> :set $ref [/file get $fileref contents]
> :set $correct ( $before + $newdata - $ref ) 
> /file set $fileref contents=$newdata
> /file set $filename contents=$correct
> } 
> :if ( $newdata >= $before ) do={
> /file set $filename contents=$newdata
> }
> :local traffic ([/file get $filename contents])
> :log warning "Limit: $limit MB"
> :local percent ($traffic*100 / $limit)
> :log warning "Use: $percent%"
> /file set $filewarn contents=$percent
> :if ($percent >= 100) do={
> /file set $filewarn contents=$percent
> /interface ppp-client set $interf disabled=yes
> }
> :if ($percent < 100 and $autointon = true) do={
> :set $status [/interface get $interf value-name=disabled] 
> :if ($status = true) do={
> /interface ppp-client set $interf disabled=no
> }
> }
> } on-error={ :log error "Error ppp-clientLimiter "};
> 
> ```

---

_[View the full topic](https://forum.mikrotik.com/t/interface-data-quota/79514)._
