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.

#!/bin/bash
if [ -d "/home/$1" ]
then
sum=0
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"
done
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 } }}'
else
echo "User $1 not found"
fi

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

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

shorturl: