sub consume { my ($filehandle) = @_; my %result; while ( defined($_ = <$filehandle>) ) { chomp; next unless /dev/; ($mount_point, $total_space, $used_space, $free_space) = split; $result{$mount_point}{total} = $total_space; $result{$mount_point}{used} = $used_space; $result{$mount_point}{free)} = $free_space; } return %result; } #### # Assume first machine is the more important one and we want to be sure we check # all its filesystems. (We can't guarantee we looked at all of the second machine's # filesystems because this just uses the same keys as machine 1 to look at machine 2. # There might be more filesystems with different names.) my @unmatched; # Section 1: matched on both. foreach my $filesystem_name (sort keys %first_machine) { print "$filesystem_name: "; my $has_differences; foreach my $type (qw(total free used)) { if (exists $second_machine{$filesystem_name}) { # Filesystem mounted on both machines my $difference = $first_machine{$filesystem_name}{$type} - $second_machine{$filesystem_name}{$type}; if ($difference) { print "$type: $difference "; $has_differences = 1; } print "\n"; # finish the line and output it delete $second_machine{$filesystem_name}; } else { push @unmatched, "$filesystem_name: "; foreach my $kind (qw(total free used)) { $unmatched[-1] .= $first_machine{$unmatched}{$kind} . " "; } $unmatched[-1] .= "\n"; } } # Second section: unmatched on first machine. if (@unmatched) { print @unmatched; } # Third section: unmatched on second machine. if (keys %second_machine) { # unprocessed filesystems on 2 not on 1. print "Unmatched filesystems on machine 2:\n"; foreach my $unmatched (sort keys %second_machine) { print "$unmatched "; foreach my $kind (qw(total free used)) { print $second_machine{$unmatched}{$kind}, " "; } print "]\n"; } }