Email update: thanks to
@elorimer 's script, there is now a second (better! in most cases) option for the vnstat-stats email process.
This adds another dependency - leveraging
@thelonelycoder 's Diversion "communication" email process - but solves other issues, including support for platforms other than gmail, secure storage of passwords, etc.
Here are the steps to replace the existing send-vnstat process:
- Make sure that Diversion's email communication is set up (
amtm > 1 (Diversion) > c (communication) > 5 (edit email settings, test email)
) with the account of your choice.
- In /jffs/scripts, create the
div-email.sh
from this source. Make sure it's executable (octal 0755).
- Update the cron job via SSH to point to this script rather than the send-vnstat script (all on a single line):
cru a vnstat_daily "59 23 * * * /opt/bin/vnstat -u && sh /jffs/scripts/vnstat-stats && sh /jffs/scripts/div-email.sh Vnstat-stats /home/root/vnstat.txt"
- Test by running
/opt/bin/vnstat -u && sh /jffs/scripts/vnstat-stats && sh /jffs/scripts/div-email.sh Vnstat-stats /home/root/vnstat.txt
- If not using send-vnstat, you can delete it (to secure your email details).
I'll be connecting with
@Martineau to make mods to the install script he has so generously created.
---
Aside: the beauty of this div-email.sh is that you can send anything that can be put into a text file as an email message. Simply pass the script name
/jffs/scripts/div-email.sh (space) "Subject line in quotes if there are spaces" (space) /path/to/text/file
- that's it.
For example, here's my script to send weekly skynet updates:
Code:
#!/bin/sh
# change the number 25 below to the number of hits you want in your report
sh /jffs/scripts/firewall stats 25 | sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' | strings > /home/root/skynet.txt
# the next command prunes whitespace from the top of the file
sed -i '1,25d' /home/root/skynet.txt
# sends a message to the system log
logger -s -t skynet_stats periodic stats complete
Which now is sent with the same
div-email.sh
script via this cron job (no additional email customization required!):
cru a skynet-wkly "2 2 * * SUN sh /jffs/scripts/skynet-stats && /jffs/scripts/div-email.sh Skynet-stats /home/root/skynet.txt"