This post will explore how to get bandwidth usage alert from your system by the email, this simple script developed by shell. Before execute it you need to install  vnstat and mail packages.

VNSTAT Command for getting bandwdith usage report.

MAIL   Send alert mail from the system.

Create a file name  bandwidth.sh and add the below code and give execute permission to run.

#  touch bandwidth.sh

#  chmod +x bandwidth.sh

#!/bin/bash
stat=`vnstat | tail -1 | awk '{print $8}'`
IP=`/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
TO_ADDRESS="alerts@thelinuxfaq.com"
SUBJECT="Bandwidth AVG Used"

#set bandwith limit in GiB size,
band=10

#get bandwith reports
   if [ $(echo "$stat >  $band" | bc) -ne 0 ]
    then
    echo $stat
    echo > /tmp/bandwidth.txt
    vnstat > /tmp/bandwidth.txt
    mail -s "$SUBJECT - $stat GiB in :$HOSTNAME-$IP" $TO_ADDRESS  < /tmp/bandwidth.txt
   else
       echo "None of the condition met"
   fi