UNIX/LINUX User's disk size calculating

I have created user's disk size eliminating script. Using this I could find out bad disk usages of users. Just copy paste into perl script, and run it on terminal. (perl script_name.pl)
#!/usr/bin/perl
#Created by :
# Nipuna Perera (nipunap at ceit dot pdn dot ac dot lk)
#
format top=
+-------------+----------------+-------------+----------+
| | |Disk | |
|Username(UID)| Home directory |Space(Mb) |Security |
+-------------+----------------+-------------+----------+
.
format STDOUT=
@<<<<<<<<<<<< @<<<<<<<<<<<<<< @>>>>>>>>>>>> @<<<<<<<<<< $uname, $home_dir, $disk, $warn +-------------+----------------+-------------+----------+ . open(PASSWD, "/etc/passwd") || die "Can n't open passwd: $!\n"; USER: while(){ chop; ($uname,$pass,$uid,$gid,$junk,$home_dir,$junk) = split(/:/); if ($uname eq "root" || $uname eq "nobody" || substr($uname,0,2) eq "uu" || ($uid <= 100 && $uid >0)){
next USER;
}
$warn = ($uid ==0 && $uname ne "root") ? "** UID=0" : "";
$warn = ($pass ne "!" && $pass ne "*") ? "** CK PASS" : $warn;

$uname .= " ($uid)";

if (-d $home_dir && $home_dir ne "/"){
$du = `du -s -m $home_dir`; chop($du);
($disk, $junk) = split(/\t/,$du); $disk .= " M";
}else{
$disk = $home_dir eq "/" ? "skipped" : "deleted";
}
write;
}
exit;

If this is not working , you can use simple shell command to get disk space of each user.
du -scm /home/*
This will provide the output in mega bytes (MB), if you use 'k' rather using 'm' as a parameter, output will be in kilobytes KB (use man du for more information)

Comments