Skip to content

Instantly share code, notes, and snippets.

@iarp
Last active October 10, 2019 02:41
Show Gist options
  • Select an option

  • Save iarp/c16197d4fd383161301f83ab7ea453ce to your computer and use it in GitHub Desktop.

Select an option

Save iarp/c16197d4fd383161301f83ab7ea453ce to your computer and use it in GitHub Desktop.
THIS IS AN OLD SCRIPT! I have not used it in many years as I haved moved onto pfSense. The purpose was to remove traffic information from my WRT54GL because the memory had filled up.
#!/bin/sh
# 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)
i=$((--i))
done
# 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
fi
done
for i in `nvram show | grep traff- | cut -f1 -d=""`; do nvram unset $i; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment