Skip to content

Instantly share code, notes, and snippets.

@taidos
Forked from rushipkar90/check_bw.sh
Created January 6, 2022 19:54
Show Gist options
  • Save taidos/e42f7024e36d71a08e60b1ac0d7d1bbf to your computer and use it in GitHub Desktop.
Save taidos/e42f7024e36d71a08e60b1ac0d7d1bbf 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