#!/usr/bin/perl/ - w # mon_users - monitor usr accounts # This script was created to monitor disk usage in peoples # home directories. It should work anywhere you will need to # edit all the paths. Prints out a nice little graph deal = ) $MAX_SPACE_ALLOWED = 15000000; %user_hash = {}; &get_user_info; &write_out_info ($MAX); exit(); sub get_user_info { $count = 0; open (USERS, "ls -al /houfiler_home/|") || die "Can't open ls -al +$!\n"; while (<USERS>) { #next if $count > 100; chop; $j, $j, $j, $j, $j, $month, $date, $time, $uname) = split; # If it starts with a '.', has capitals or is "" its not a username next if ($uname =~ /tim/ || $uname =~ /\./ || $uname eq "" || (lc ($un +ame) ne $uname)) ; # Make Home Directory out of username $home_dir = "/houfiler_home/$uname"; $du = `du -s -k $home_dir`; chop $du; ($disk,$junk) = split(/\t/,$du); # Store everything in a Hash Table $user_hash{"$uname"} = $disk; $count++; # print "$count\n"; } } sub sortHashByNum { $user_hash {$b} <=> $user_hash{$a}; } sub write_out_info { #header at top of each page of the report format OUTPUT_TOP = Disk Username Home Directory Space Usage (100% = 15G +) ---------------------------------------------------------------------- +--- . $~ = "OUTPUT_TOP"; write; # format for each line written to handle OUTPUT format STDOUT = @<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<@<<<<<<<<<<<<<<<< +<<<<<< $uname, $home_dir, $disk, $level . $~ = "STDOUT"; foreach $uname ( sort sortHashByNum keys %{user_hash}) { $uname =~ s/\d//g; # Make Home Directory out of username $home_dir = "/houfiler_home/$uname"; $disk = $user_hash{$uname}; $level = '*' x int (($disk*20)/$MAX_SPACE_ALLOWED+0.5); $level .= '-' x (20 - length ($level)); $level = "|".$level."|"; $disk .= "K"; # Write out formatted line to standard output write; } }
2001-03-03 Edit by Corion : Added <CODE> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DiskUsage.pl
by AgentM (Curate) on Feb 14, 2001 at 00:13 UTC | |
by JSchmitz (Canon) on Feb 15, 2001 at 01:48 UTC | |
|
(sacked) Re: DiskUsage.pl
by sacked (Hermit) on Feb 13, 2001 at 23:11 UTC | |
|
Re: DiskUsage.pl
by jeroenes (Priest) on Feb 14, 2001 at 19:12 UTC |