http://qs321.pair.com?node_id=49030


in reply to Unix disk space reports

This seems much too complicated for my liking.

I really don't like the way it needs to create a temporary file, and that it writes it output out to a fixed file, rather than STDOUT, thus letting me redirect it, or play with it in some other way. I'd go for something more along the lines of:

use strict; my %space; while (<>) { next unless m#^/#; next if m#^/proc#; next unless m#^[^ ]* *([^ ]*) *[^ ]* *([^ ]*) *[^ ]*#; $space{$ARGV}{total} += $1; $space{$ARGV}{free} += $2; } foreach my $host (sort keys %space) { printf "%s: %dk free, out of %dk, (%.2f%%)\n", $host, $space{$host}{free}, $space{$host}{total}, $space{$host}{free} / $space{$host}{total} * 100; }
Then I'd call it as: perl ~/dfk hosts/* > report

Playing with the format of the output is then trivial.

If you really want to be able to view the intermediate 'space' file, then you could add a command line parameter for it (including the name of the output file?).

Tony