Real Reseller Usage in cPanel

by dt on September 7th, 2009

Usually, cPanel display lower disk space usage than real. This happens from two reasons: first, mysql databases are not counted (because quota on mysql may corrupt data) and second, all files created from PHP are owned by nobody user (if PHP is compiled as apache module and without SuPHP – but this is by default). So, if you want to see how much space an reseller use for all his accounts, use the script below. Input parameter is reseller username.

if [ -d "/home/$1" ]
for i in `grep -l $1 /var/cpanel/users/* | sed "s/\/var\/cpanel\/users\///"`; do
du=`du -sk /home/$i /var/lib/mysql/$i* 2>/dev/null | awk '{sum+=$1}END{print sum}'`
let sum=$sum+$du
echo -e "$du\t$i"
echo "-----------------------------"
echo -ne "TOTAL:\t"
echo $sum | awk '{sum+=$1}END{hum[1024**3]="T";hum[1024**2]="G";hum[1024]="M";for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f%s\n",sum/x,hum[x];break } }}'
echo "User $1 not found"

Save it as a file, for example make it executable chmod +x and call it with the reseller username as parameter. The result will be similar to this:

root@s1 [~]# ./ reseller1
9376    user1
108892  user2
470108  user99
TOTAL:  8.14G