Posted: Sat Feb 05, 2011 6:26 Post subject: Bandwidth Reporting Script based on your true Billing Month
This is my first adventure in router scripting. I Only discovered and implemented DD-WRT on my new router a week ago.
I created the script for and tested with DD-WRT v24-sp2 (08/07/10) std (SVN revision 14896). The script does NOT work with the mini version (not sure about others). It is built on top of script "Email_Bandwidth_Usage_Daily" from http://www.dd-wrt.com/wiki/index.php/Useful_Scripts.
Program uses DD-WRT Traffic data to supply bandwidth usage for your billing month.
Usage: <program> <billing start day> <display choice>
billing start day must be a day from 1-28
display choice - optional parameter - "GB" to display monthly #s in GB, default is MB
Examples:
/bin/sh email_monthly_bandwidth.sh 28 GB
/bin/sh email_monthly_bandwidth.sh 1
after running this >/bin/sh email_monthly_bandwidth.sh 28
The program will send an email with the following report with Bandwidth remaining, usage for monthly billing period to date and yesterday's total:
-------------------
Bandwidth Remaining: 167661 MB
Days left in period: 22
Totals for Period Starting 1/28/2011
Incoming: 35861 MB
Outgoing: 1278 MB
Total : 37139 MB
Totals for 2/4/2011
Incoming: 2231 MB
Outgoing: 95 MB
Total : 2326 MB
-------------------
You will need to update 2 things.
The sendmail command in fcn_mail needs to reflect your ISP's SMTP server and sending address as well as the recipient email.
Secondly there is a variable MONTHLY_CAP that is currently set to 204800 (200GB cap). This is in MB.
I have accounted for all date logic including leap years. I have not tested all scenarios so there may still be bugs left.
Calculating in this OS is limited to integers so using GB for bandwidth takes away some accuracy. If there is a way around this let me know. Because of the integer limitation I used MB in yesterday's totals.
Let me know what you think!
Edit Feb 8th 2011
New release, ver 0.2
Had to change zero stripping logic when running
date commands. 08 and 09 do not work with "let"
commands. 07 and below are fine...Weird!
Last edited by tangled111 on Sun Mar 27, 2011 12:12; edited 1 time in total
Posted: Mon Feb 21, 2011 21:44 Post subject: Version 0.3
Hi,
I changed the script again to my preferences and needs. <NOTE: You need to register to see attached script!>
I changed the report a bit. Took out yesterday's totals because I really don't care about that and I added %.
The report that is emailed now looks like this:
Quote:
Total Monthly Bandwidth: 204800 MB
Bandwidth Remaining: 73888 MB or 36%
Days left in period: 6
Totals for Period Starting 1/28/2011
Incoming: 125829 MB
Outgoing: 5083 MB
Total : 130912 MB
I have also changed the frequency of the email reports. I have the script scheduled to run once a day but I got tired of receiving daily emails.
Now the report only emails on specific trigger points.
It will email once when bandwidth remaining goes under 75%, then once under 50%, once under 25%, and then every time executed once below 10%.
I left version 0.2 in case you prefer the older version.
Enjoy!
Last edited by tangled111 on Sun Feb 27, 2011 1:24; edited 1 time in total
Posted: Wed Feb 23, 2011 15:37 Post subject: Re: Email bandwidth report on a threshold/cap
s_m_turner wrote:
Hi tangled111
I'm trying to create a script that will Email me on the 28th of each month, if the bandwidth has reached on gone over a set limit.
e.g if the total bandwidth = or > 10GB
Any help would be appreciated.
Cheers
To have the script email you only on the 28th setup the cron to run the job on the 28th of every month.
To have the script email you on the condition that total bandwidth >= 10240 MB modify version 0.3 of my script by replacing lines 295-324 with the following:
Quote:
##Threshold value is in MB
threshold=10240
if [ $billMonthTotal -ge $threshold ]
then
fnc_mail "Bandwidth Report" "$msg" "/tmp/bwmail.log"
fi
Program uses DD-WRT Traffic data to supply bandwidth usage for your billing month.
Usage: <program> <billing start day> <display choice>
billing start day must be a day from 1-28
display choice - optional parameter - "GB" to display monthly #s in GB, default is MB
Examples:
/bin/sh email_monthly_bandwidth.sh 28 GB
/bin/sh email_monthly_bandwidth.sh 1
after running this >/bin/sh email_monthly_bandwidth.sh 28
The program will send an email with the following report with Bandwidth remaining, usage for monthly billing period to date and yesterday's total:
-------------------
Bandwidth Remaining: 167661 MB
Days left in period: 22
Totals for Period Starting 1/28/2011
Incoming: 35861 MB
Outgoing: 1278 MB
Total : 37139 MB
Totals for 2/4/2011
Incoming: 2231 MB
Outgoing: 95 MB
Total : 2326 MB
-------------------
You will need to update 2 things.
The sendmail command in fcn_mail needs to reflect your ISP's SMTP server and sending address as well as the recipient email.
Secondly there is a variable MONTHLY_CAP that is currently set to 204800 (200GB cap). This is in MB.
I have accounted for all date logic including leap years. I have not tested all scenarios so there may still be bugs left.
Calculating in this OS is limited to integers so using GB for bandwidth takes away some accuracy. If there is a way around this let me know. Because of the integer limitation I used MB in yesterday's totals.
Let me know what you think!
Edit Feb 8th 2011
New release, ver 0.2
Had to change zero stripping logic when running
date commands. 08 and 09 do not work with "let"
commands. 07 and below are fine...Weird!
1) Enable and setup ssh for your router through dd-wrt web interface
2) Enable cron, also through the web interface
3) scp the script to the /tmp dir and test it out.
You can run from the /tmp dir, but if you restart your modem everything in /tmp is wiped out.
4) Enable jffs and "clear" jffs to create space. This will allow you to keep the script in the jffs space that won't get removed after a modem reboot.
5) Create cron job in the web tool, save, reboot
Posted: Sun Mar 27, 2011 4:39 Post subject: Re: Bandwidth Reporting Script based on your true Billing Mo
I do not have an option to enable JFFS.. I have the micro version running. I looked all over this thing and couldn't find it. But yes, those instructions look VERY easy.. just those options do not show up for me.
Also do not have SSH but have cron.
tangled111 wrote:
gdlgiii wrote:
But how do you upload the script into the router? How is it called? Via CRON job? Is this automated??
You definitely want to automate the script through cron. I have it running once a day.
1) Enable and setup ssh for your router through dd-wrt web interface
2) Enable cron, also through the web interface
3) scp the script to the /tmp dir and test it out.
You can run from the /tmp dir, but if you restart your modem everything in /tmp is wiped out.
4) Enable jffs and "clear" jffs to create space. This will allow you to keep the script in the jffs space that won't get removed after a modem reboot.
5) Create cron job in the web tool, save, reboot
Posted: Sun Mar 27, 2011 12:11 Post subject: Re: Bandwidth Reporting Script based on your true Billing Mo
gdlgiii wrote:
I do not have an option to enable JFFS.. I have the micro version running. I looked all over this thing and couldn't find it. But yes, those instructions look VERY easy.. just those options do not show up for me.
Also do not have SSH but have cron.
Yup, this will not work with micro version. I found that micro version doesn't even have all the commands needed to run the script. You can't even do an "ls" command on mini. I should have put this step in first:
0) Make sure your dd-wrt version is > mini
I actually don't know what the minimum required version is. I developed and tested this script on DD-WRT v24-sp2 (08/07/10) std (SVN revision 14896)
Hello, sorry for digging up an old thread but this scripts looks very useful to me.
I am sorta a ddwrt n00b though (but I did get ddwrt installed so maybe I got some skillz?) and need some help firstly,
'Modifications needed for your use update the sendmail command in fcn_mail to reflect your ISP's SMTP server and sending address as well as the recipient email'
I am not sure what to do here, I would like to use my gmail account if possible. I don’t ever use my ISP email address, but is it needed for the sender and I can use gmail as the reciever?
Also, is there a way I can test email to make sure it is sending instead of waiting for a bandwith limit?