?
Solved

script for disk summary by file ownership

Posted on 2003-03-24
4
Medium Priority
?
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 84

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

764 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