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 and add the below code and give execute permission to run.

#  touch

#  chmod +x

stat=`vnstat | tail -1 | awk '{print $8}'`
IP=`/sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
SUBJECT="Bandwidth AVG Used"

#set bandwith limit in GiB size,

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