- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl "malfunction"
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2008 11:11 AM
тАО10-06-2008 11:11 AM
I am not a perl master by any means, but I have attached a script that gives the amount of space used by each user in /home. My problem is that it is not reporting all users, it is only reporting some users. What is wrong with this? Can anyone tell me what I am missing?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2008 11:59 AM
тАО10-06-2008 11:59 AM
Re: Perl "malfunction"
You will avoid chasing silly mistakes if you always use the 'strict' and 'warnings' pragma!
use strict;
use warnings;
If this is not reporting all users, perhaps it is because you have '/home' directories smaller than 1% of the total.
I regret to say that this Perl script isn't very Perl-ish. You might want to look into the 'File::Find' module and the 'stat()' function. The module will search as directory and 'stat()' can tell the size of files and/or directories within. You could also use 'readdir()' to read entries in your directories. Essentially your Perl script uses a hash to tally and report overall directory sizes, but it makes lots of external calls to do so.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2008 01:01 PM
тАО10-06-2008 01:01 PM
Re: Perl "malfunction"
# cd /home
# du -sk *
BTW as an addition to what JRF said, a perl way to check the size of a file without a system call or perl function, is using '-s $file', which will return the size of $file
--8<--- untested braindump:
use strict;
use warnings;
use File::Find;
chdir "/home";
my $space;
foreach my $user (glob "*) {
find (sub { $space{$user} += -s $_ },$user);
}
printf "%9d %s\n", $space{$_}, $_ for sort { $space{$a} <=> $space{$b} } keys %space;
-->8---
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2008 01:48 PM
тАО10-06-2008 01:48 PM
SolutionBut I can see some merrit in the script.
It starts to build an array, but does not (yet) use it.
It could learn gather data first just once and then print when all data is there.
Here is a slight improvement suggestion.
It sorts by descending usage.
Note how it handles Totat in the loop.
Also Untested (on hpux. HP test-drive is now gone and I still have to set up an alternative or re-boot my rx to run hpux instead of VMS. I did give it a quick run on my linux music-player :-).
#!/usr/contrib/bin/perl
my $home_thresh = 1 ;
my $top = 10;
foreach (`du -sk /home/* 2> \/dev\/null` ) {
chop ;
($home_kb,$home_dir) = split (/\s+/);
$home_total += $home_kb;
$homes_size{$home_dir} = $home_kb ;
}
$homes_size{"Total"} = $home_total;
print "Top $top users larger than $home_thresh%\n";
foreach (sort { $homes_size{$b} <=> $homes_size{$a} } keys %homes_size ) {
$home_pct = int(($homes_size{$_} / $home_total) * 100) ;
last unless $top--;
last if $home_pct < $home_thresh;
print "$_ ($homes_size{$_} kb) is $home_pct% \n" ;
}
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2008 04:24 AM
тАО10-07-2008 04:24 AM