Posted: Sat Jun 26, 2010 6:17 Post subject: Daily email with the previous day's bandwidth usage?
Does anyone already happen to have a script for that? I see how in this thread that sendmail can be used, and I know that the traff data is available, but that's about as far as I've gotten.
For the ttraff nvram variables you can view them with this.
nvram show | grep traff-
The variables are named traff-MM-YYYY. The data is a space separated list of values for each day's download:upload. At the end is a bracketed set of totals for the month.
Have fun reading the man pages for date, cut, etc. _________________ Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
Right, I know where the data is, but it's the entire rest that could prove interesting. At least I have some clues with date/cut. It's a little surprising that this hasn't been done before. A daily report, weekly, whatever.
If anyone has an interest in doing this, or knows where it's been done, I'm still interested. There's no way I'm going to be able to do it with the information I have so far.
The user and pass may be required for sendmail via SMTP.
The mess of nested apostrophes can be avoided if you can create script files on a permanent filesytem.
The code can be pasted via the web GUI into the startup script or, if that is bugged, into the firewall script. I couldn't get this to work via cron_jobs even while bypassing the web GUI and modifying nvram directly. I think you are better off sticking with simple calls to scripts in any crontab files.
Also, the sleep is there because the crontab files can be flushed if you are adding to them before cron has started.
Can you show how the script is modified to use SMTP Auth? Also can you tell me if the email is sent when the script is done processing?
Great work thanks _________________ Location (urban) - 1x Linksys EA8500 (AP wlan0 & wlan1 enabled)
1x Asus 68u (Repeater Bridge w/VAP) - wl0 disabled
1x Asus 87u (Client Bridge) - wl1 disabled
Add -u"user" -p"password" to the sendmail arguments.
After you add the line to your startup script, you will need to reboot the router (or run the command manually as well). Every boot, a script will be stashed in memory (/tmp/bwmail). You can edit that file directly and run it at any time to test if the mail is being sent. Look in /tmp/bwmail.log for output or errors. If you make changes to bwmail directly, make sure they are reflected in the startup script or they will revert at next reboot. Also, note the startup script is more complicated since it has multiple nested apostrophes.
A cron job is scheduled for 12:05AM at the start of a new day (5 0 * * *) and the script will not be executed until that time. Do not schedule it to run before midnight since it simply looks for the previous day's totals. Also, if you run it later in the day, the previous day's total will stay static, but you will have to add in some math if you want the monthly total for a previous time.
Nice script, I added it to the useful scripts page.
http://www.dd-wrt.com/wiki/index.php/Useful_Scripts#Email_Bandwidth_Usage_Daily _________________ Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
To test it, I've tried running /tmp/bwmail manually, but mail is not sending or bouncing. bwmail.log was written once, but it's zero bytes. Can you take a look at bwmail to see if anything jumps out at you? I changed the above two items back for the purposes of posting here. I have a fairly recent build (14583) but can update it if it turns out that's the problem. Thanks.
Code:
sendmail -S"smtp.comcast.net" -f"sender@comcast.net" -F"DD-WRT" -d"comcast.net" -s"Bandwidth Report" -m"$(nvram get $(date +traff-%m-%Y) | awk '{print $'$(expr $(date +%d) - 1)', $NF}' | sed -e 's;\([^:]*\):\([^ ]*\) \[\([^:]*\):\([^]]*\)];Totals for Yesterday\nIncoming: \1 MB\nOutgoing: \2 MB\n\nTotals for Month to Date\nIncoming: \3 MB\nOutgoing: \4 MB\n;')" me@gmail.com > /tmp/bwmail.log 2>&1
Joined: 31 Aug 2009 Posts: 2448 Location: Third Rock from the Sun
Posted: Tue Aug 24, 2010 21:57 Post subject:
tc23emp wrote:
Add -u"user" -p"password" to the sendmail arguments.
After you add the line to your startup script, you will need to reboot the router (or run the command manually as well). Every boot, a script will be stashed in memory (/tmp/bwmail). You can edit that file directly and run it at any time to test if the mail is being sent. Look in /tmp/bwmail.log for output or errors. If you make changes to bwmail directly, make sure they are reflected in the startup script or they will revert at next reboot. Also, note the startup script is more complicated since it has multiple nested apostrophes.
A cron job is scheduled for 12:05AM at the start of a new day (5 0 * * *) and the script will not be executed until that time. Do not schedule it to run before midnight since it simply looks for the previous day's totals. Also, if you run it later in the day, the previous day's total will stay static, but you will have to add in some math if you want the monthly total for a previous time.
What about using port 465 for smtp.gmail? Is it possible to add this argument?
tc23emp wrote:
The script should look exactly like this:
Code:
#!/bin/sh
sendmail -S"smtp.comcast.net" -f"sender@comcast.net" -F"DD-WRT" -d"comcast.net" -s"Bandwidth Report" -m"$(nvram get $(date +traff-%m-%Y) | awk '{print $'$(expr $(date +%d) - 1)', $NF}' | sed -e 's;\([^:]*\):\([^ ]*\) \[\([^:]*\):\([^]]*\)];Totals for Yesterday\nIncoming: \1 MB\nOutgoing: \2 MB\n\nTotals for Month to Date\nIncoming: \3 MB\nOutgoing: \4 MB\n;')" me@gmail.com > /tmp/bwmail.log 2>&1
At this point a cron job should be added to run the script file? _________________ Peacock Thread-FAQ -- dd-wrt Wiki
EDIT: I was looking at a completely different shell, just check the busybox manual.
I'm not really sure. On my firmware, sendmail points to exim. You can actually use: man exim to get more information or google which arguments you need to use with exim.
Last edited by tc23emp on Wed Aug 25, 2010 1:14; edited 1 time in total
I'm not really sure. On my firmware, sendmail points to exim. You can actually use: man exim to get more information or google which arguments you need to use with exim.
Does that mean you're using optware? Sendmail is handled by busybox by default.
root@DD-WRT:~# ls -l /usr/sbin/sendmail
lrwxrwxrwx 1 root root 17 May 21 14:24 /usr/sbin/sendmail -> ../../bin/busybox
ps. sorry about the crediting the wrong person. I just went to correct it and you already had. _________________ Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)