DD-WRT Clear Old Bandwidth Logs

I've been using DD-WRT firmware on my routers for many years now. I found after 2-3 years of continuous usage, the internal memory would fill up, and strange things would start to happen. I found that on the Port Forwarding page, rows would start disappearing, when I would add a new row the original rows would begin to show up, and various other issues.

Through googling and such I figure out it was happening because the internal memory was getting close to capacity (or was at it already).

I found this script somewhere online last year sometime.

  1. Telnet into the router, create a file and paste the below code.
  2. Then run it.
# Delete traffic data leaving X number of months, includes current month
# If command line parameter is not provided then default to 1, which keeps current month only
if [ $1 -gt 0 ]; then i=$1; else i=1; fi
# Get current date in a format compatable with the date -d switch
d=`date +%Y.%m.%d-%H:%M`
# Loop back through the calendar X number of months
# each iteration lands at the last day of the previous month
while [ $i -gt 0 ]; do
  d=$(date -D %s -d $(( $(date -d $d +%s)-( $(date -d $d +%d)*86400))) +%Y.%m.%d-%H:%M)
# Compare date derived above with nvram traffic dates, both in terms of YYYYMM
for i in `nvram show |grep traff- |cut -d= -f1`; do
  if [ $(echo $i |cut -c7-13 |awk -F'-' '{print $2,$1}' |cut -c1-4,6-7) -le $(date -d $d +%Y%m) ]; then
    nvram unset $i