How to find the bandwidth utilized by individual users via SSH?

1)Create a new file with following code.
2) chmod +x bandwidth
3) Then execute the file with 2 parameters viz. month and year.

vi bandwidth

#!/bin/bash

cd /var/cpanel/bandwidth/
ls | grep -v “\.” | xargs -n 1 -izzz sh -c “echo -n zzz \” = \”; egrep \”^$1\..*\.$2-all\” zzz | awk -F’=’ ‘START {bytes=0} { bytes+=\$2 } END {print bytes/1024/1024 \” MB\”}'”
cd –

Usage:

./bandwidth month year

Eg To see top 10 BW taking users in January 2012

./bandwidth 1 2012 | sort -nrk 3 | head -10

The above will show the result in the descending order. It will display the  highest BandWidth usage account first.

User names can be related with domain names from /etc/trueuserdomains 

Leave a Reply