- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Perl: Sort
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
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-12-2006 01:05 AM
тАО10-12-2006 01:05 AM
/home/usera (xxxxxxxkb) 45%
/home/userb (xxxxxxxkb) 20%
/home/userc (xxxxxxxkb) 5%
Thanks,
#!/usr/contrib/bin/perl
# Show the percentage of total used space in /home to each user
# 11/18/02 BRS
$home_thresh = 1 ; # won't print if it isn't more than 1%
# Get the size of each users home directory
# sub homes_report {
$home_total = `du -sk /home 2> \/dev\/null`;
($home_total,$nothing) = split(/\s+/,$home_total) ;
print "/home's total usage is $home_total kb \n" ;
foreach (`du -sk /home/* 2> \/dev\/null` ) {
chop ;
($home_kb,$home_dir) = split (/\s+/);
$homes_size{$home_dir} = $home_kb ;
$home_pct = int(($home_kb / $home_total) * 100) ;
if ( $home_pct > $home_thresh ) {
print $home_dir ($home_kb kb) is $home_pct% \n" ;
}
}
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2006 01:23 AM
тАО10-12-2006 01:23 AM
Re: Perl: Sort
#!/opt/perl/bin/perl
use strict;
use warnings;
# Show the percentage of total used space in /home to each user
my $home_thresh = 1 ; # won't print if it isn't more than 1%
# Get the size of each users home directory
# sub homes_report {
(my $home_total = `du -sk /home 2> /dev/null`) =~ s/\s.*//s;
print "/home's total usage is $home_total kb \n" ;
my %homes;
for (`du -sk /home/* 2>/dev/null`) {
chomp;
my ($home_kb, $home_dir) = split m/\s+/;
$homes{$home_dir}{size} = $home_kb;
my $home_pct = int (($home_kb / $home_total) * 100);
$home_pct > $home_thresh or next;
$homes{$home_dir}{pct} = $home_pct;
}
foreach my $dir (sort { $homes{$b}{pct} <=> $homes{$a}{pct} } keys %homes) {
printf "%6.2f%% %s\n", $homes{$dir}{pct}, $dir;
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2006 11:01 PM
тАО10-12-2006 11:01 PM
SolutionTry this instead
#!/opt/perl/bin/perl
use strict;
use warnings;
my $users = shift || "/users";
# Show the percentage of total used space in /home to each user
my $home_thresh = 1.; # won't print if it isn't more than 1%
# Get the size of each users home directory
# sub homes_report {
(my $home_total = `du -sk $users 2> /dev/null`) =~ s/\s.*//s;
print "$users\'s total usage is $home_total kb \n";
$home_total > 0 or exit;
my %homes;
for (`du -sk $users/* 2>/dev/null`) {
chomp;
my ($home_kb, $home_dir) = split m/\s+/;
$homes{$home_dir}{size} = $home_kb;
my $home_pct = int (($home_kb / $home_total) * 100);
$homes{$home_dir}{pct} = $home_pct;
}
foreach my $dir (sort { $homes{$b}{pct} <=> $homes{$a}{pct} } keys %homes) {
$homes{$dir}{pct} > $home_thresh and
printf "%6.2f%% %s\n", $homes{$dir}{pct}, $dir;
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2006 12:39 AM
тАО10-13-2006 12:39 AM
Re: Perl: Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2006 12:45 AM
тАО10-13-2006 12:45 AM
Re: Perl: Sort
your a genius!!!!!!!!!
Many thanks and 25 pts. from me *1*
Best wishes
see you
Volkmar