User storage report in Linux

User storage report in Linux

-

Here is my way of doing it with Perl.

#!/usr/bin/perl

printf "Generating overview over user account storage amounts..\n\n";

opendir(DIR, '/home/');
@dirs = readdir(DIR);
closedir(DIR);

foreach $dir (@dirs) {
if($dir ne '..' && $dir ne '.') {
$dir_size = `du -h --max-depth=0 /home/$dir`;
$dir_size =~ s/\s.*//;
printf "$dir : $dir_size";
}
}

printf "\n";

Put code in a file and chmod 755 to it to run as either console command or through a website.

To show through a website you can use something like this.

#!/usr/bin/perl
$output = `cat /home/myuser/scripts/thescript.pl`;
print "Content-Type: text/html\n\n";
print '<pre>'. $output .'</pre>';

Here is how the output looks like

root@Mybox adminscripts # ./userstorage
Generating overview over user account storage amounts..

User1 : 608K
User2 : 28M
User4 : 300M
MyUser : 400K

root@Mybox adminscripts #

Leave a Reply