1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 5 my @headers = qw(name size used free capacity mount); 6 my @df = `df -k`; 7 shift @df; # get rid of the header 8 9 my %devices; 10 for my $line (@df) { 11 my %info; 12 @info{@headers} = split /\s+/, $line; # note the hash slice 13 $info{capacity} = _percentage_to_decimal($info{capacity}); 14 $devices{ $info{mount} } = \%info; 15 } 16 17 # Change 12.3% to .123 18 sub _percentage_to_decimal { 19 my $percentage = shift; 20 $percentage =~ s{%}{}; 21 return $percentage / 100; 22 } 23 # Now the information for each device is in a hash of hashes. 24 25 # Show how much space is free in device /dev/ad4s1e 26 print $devices{"/production/log"}{free} ; 27 print "\n"; 28 for my $info (values %devices) { 29 # Skip to the next device if its capacity is not over 60%. 30 next unless $info->{capacity} > .10; 31 32 # Print some info about each device 33 printf "%s is at %d%% with %dK remaining.\n", 34 $info->{mount}, $info->{capacity}*100, $info->{free}; 35 }