?
Solved

script for disk summary by file ownership

Posted on 2003-03-24
4
Medium Priority
?
173 Views
Last Modified: 2010-03-05
Hi all.,
I am wishing if somebody can help me out with my problem.
I need to scan the file system table(/etc/mtab ot /etc/vfstab) and then recursively go thru each sbdirectory counting the number of blocks owned by users listed in /etc/passwd
So the final output would be like
<number_of_blocks> <user_name>
I know that we can use "du -ks" to get the number of blocks used but it doesnt give me user name.
An example output for clarifying would be

/export/home
73686    root
4654     user1
3544     user2

Appreciate your support on this.
Thanks
Paddy
0
Comment
Question by:peepz
  • 3
4 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 380 total points
ID: 8195103
use File::Find;
open F,"</etc/mtab" or die "Can't open /etc/mtab $!";
while( <F> ){
    my $root = (split)[1];
    local %b=();
    print "$root\n";
    find(sub{
        my ($uid, $blocks) = (lstat)[4,12];
        $b{$uid} += $blocks;
         },
         $root
    );
    for( sort{$b{$b}<=>$b{$a}} keys %b ){
       print $b{$_},"\t".getpwuid($_)."\n";
    }
}
0
 

Author Comment

by:peepz
ID: 8195277
Thanks ozo for the prompt response.
Let me put this code to work and I'll get back shortly.
0
 

Author Comment

by:peepz
ID: 8195634
Thanks ozo for the prompt response.
Let me put this code to work and I'll get back shortly.
0
 

Author Comment

by:peepz
ID: 8195791
Thank you so much.Just works fine except that I need to suppress the errors for "Permission Denied" but I guess that should disappear if I run it as root.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question