Clear Bandwidth Data - Keeping the number of months you want

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload
Author Message
jft
DD-WRT Novice


Joined: 01 Jun 2012
Posts: 4

PostPosted: Wed Jul 18, 2012 12:29    Post subject: Clear Bandwidth Data - Keeping the number of months you want Reply with quote
Run this script with a parameter that defines the number of months of traff data to keep.

Cron:
45 23 1 * * root sh /jffs/delTraffData.sh 4

The parameter 4 tells the script to keep the current month and the previous 3 months.

Run any day of the month.

Code:

#!/bin/sh
#delete traff data leaving i number of months, includes current month
#if 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 thur the calendar i 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)
  i=$((--i))
done
#compare date derived above with nvram traff 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
  fi
done

Sponsor
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum