Find user Bandwidth via SSH shell (CPanel/WHM)

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 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s