Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Created September 25, 2015 16:25
Show Gist options
  • Select an option

  • Save rushipkar90/c51b1432f061a4c81ede to your computer and use it in GitHub Desktop.

Select an option

Save rushipkar90/c51b1432f061a4c81ede to your computer and use it in GitHub Desktop.
check_bw.sh
#!/bin/bash
# Display bandwidth usage
# By [email protected] 2012/04/17
if [ $# -lt 2 ];
then echo "Error: wrong number of arguments";
echo "Usage: $0 <username or site name> <traffic type> <month> <year> e.g. $0 stupi402 imap 4 2012"
echo "If no month and/or year are specified, script will display data for current month/year.";
echo "Also Please note that cPanel doesn't seem to save per-domain bandwidth for imap, ftp, pop and smtp."
exit 1;
else
if [ $2 != 'all' ] && [ $2 != 'imap' ] && [ $2 != 'pop' ] && [ $2 != 'http' ] && [ $2 != 'ftp' ] && [ $2 != 'smtp' ];
then echo "Error: invalid traffic type. Possible options: all, imap, pop, smtp, http, ftp";
exit 1;
fi
egrep "^${3-`date +%-m`}.*.${4-`date +%Y`}-$2" /var/cpanel/bandwidth/$1|awk -F'=' 'START {bytes=0} { bytes+=$2 } END {print bytes/1024/1024 " MB"}';
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment