#!/usr/bin/perl # # disk-usage.pl - print summary info about disk usage # by all users # # Developed by Lubomir Host 'rajo' # Copyright (c) 2005 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2005-09-22 - created # # Usage: # perl disk-usage.pl [/dev/hda1] [/dev/md3] # # $Platon: scripts/perl/filesystem/disk-usage.pl,v 1.3 2006-03-15 08:34:32 rajo Exp $ use strict; use Data::Dumper; $| = 1; my $user_stat = { }; my $glob_stat = { }; open(PASSWD, ") { next if $line !~ m#/home/#; # ignore system users; my ($user, $passwd, $uid, $gid, $info, $homedir, $shell) = split(/:/, $line); open(QUOTA, "quota -v $user|") or warn "Can't get quota for user '$user'"; my $qline = ; # skip 2 lines $qline = ; # skip 2 lines while ($qline = ) { # TODO: bad info if grace chomp $qline; # only a one word on the line. It is a long device name (LVM partition or something) if (scalar(grep { $_ ne '' } split(/\s+/, $qline)) == 1) { # grab 1 line $qline .= ; chomp $qline; } my ($filesystem, $blocks, $b_quota, $b_limit, $files, $f_quota) = grep { $_ ne '' } split(/\s+/, $qline); $user_stat->{$user}->{$filesystem}->{blocks} = $blocks; $user_stat->{$user}->{$filesystem}->{files} = $files; $glob_stat->{$filesystem}->{blocks} += $blocks; $glob_stat->{$filesystem}->{files} += $files; } close(QUOTA) } close(PASSWD); #print Dumper($user_stat, $glob_stat); my @fs_list; if (scalar(@ARGV) > 0) { @fs_list = @ARGV; } else { @fs_list = sort keys %$glob_stat; } print "user\t", join("\t\t", @fs_list), "\n"; print "-" x 60; foreach my $user (sort keys %$user_stat) { print "\n$user\t| "; foreach my $filesystem (@fs_list) { printf("%04.2f\t", ($glob_stat->{$filesystem}->{blocks} == 0 ? 00.00 : 100 * $user_stat->{$user}->{$filesystem}->{blocks} / $glob_stat->{$filesystem}->{blocks}) ); } } print "\n"; # vim: ts=4 # vim600: fdm=marker fdl=0 fdc=3