I bought a router with gargoyle pre-installed recently and LOVE the quotas and bandwidth monitoring features. Before, my family of four was constantly struggling to stay below our (somewhat paltry) monthly quota from our ISP and never sure which device or devices were sucking down all our bandwidth.
I have set up a monthly quota for the network and daily quotas for each user. It works great, but I would like to make one tweak. I've been logging in once a week or so and updating the daily quotas based on how much of our monthly quota is left, and I would like to automate that.
I would like to ssh into the router and write a script to update the per-user (nightly) quotas based on how much bandwidth is left for the month.
I think I found the quotas in /overlay/usr/data/quotas/, but I'm not quite sure what their format is. They look like this:
1385485201
0.0.0.0 57689303
Is the first line the total and the second the current usage? If not, where can I find the current usage?
Also, more broadly, are there any issues or pitfalls I should be aware of in trying this?
Command line reference for editing quotas
Moderator: Moderators
Re: Command line reference for editing quotas
Poking around -- it looks like I can rig something up with and
Unless there's a better way to find current usage? didn't seem to offer any hooks for finding usage.
Code: Select all
print_quotas | grep quotaUsed
Code: Select all
uci set firewall.quota_X.combined_limit
Code: Select all
uci show firewall
Re: Command line reference for editing quotas
I rigged something up and added it to /etc/crontabs/root. Suggestions welcome. The ISP's quota resets on the 14th of each month, and I want user 1 to get 1/ 7 of the quota and users 2-4 to get 2/7 each.
Code: Select all
# Total limit
TOTAL_LIMIT=`uci get firewall.quota_1.combined_limit`
# echo Total limit: $TOTAL_LIMIT
# Days left
DAY=`date +%d`
MONTH=`date +%m`
YEAR=`date +%Y`
if [ $DAY -gt 13 ]; then
MONTH=$(($MONTH + 1))
if [ $MONTH -eq 13 ]; then
MONTH='01'
YEAR=$(($YEAR + 1))
fi
fi
DAYS_LEFT=$(( ( $(date -d "$YEAR-$MONTH-14 0:00" "+%s") - $(date "+%s") ) / 86400 + 1))
# echo Days left: $DAYS_LEFT
# Used so far
USED_SO_FAR=`print_quotas | grep quotaUsed | egrep -o '=.+' | egrep -o ' [0-9]+,' | egrep -o '[0-9]+' | head -n1`
# echo Used so far: $USED_SO_FAR
# Amount remaining
AMOUNT_REMAINING=$(($TOTAL_LIMIT - $USED_SO_FAR))
# echo Amount remaining: $AMOUNT_REMAINING
# Per user
ONE_SEVENTH=$(($AMOUNT_REMAINING / $DAYS_LEFT / 7))
TWO_SEVENTHS=$((ONE_SEVENTH * 2))
# echo 1/7: $ONE_SEVENTH
# echo 2/7: $TWO_SEVENTHS
# Set the limits
uci set firewall.quota_2.combined_limit=$ONE_SEVENTH
uci set firewall.quota_3.combined_limit=$TWO_SEVENTHS
uci set firewall.quota_4.combined_limit=$TWO_SEVENTHS
uci set firewall.quota_5.combined_limit=$TWO_SEVENTHS