http://www.perlmonks.org?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

Replies are listed 'Best First'.
Re: Re: Unix disk space reports
by halxd2 (Monk) on Jan 02, 2001 at 19:43 UTC
    I agree my script does limit general usage; however, I was working to get a report that had the format I wanted for my boss. As for keeping the temp files I usualy keep them until I'm very sure I'm getting everything I what out of the script. I guess I just live in debugland.
      I want the same kind of report which has the capablity of showing the diskpace status for the past month. Can some help?

        You could start by showing us where in your code you have difficulties. As the program currently just displays the status quo, I imagine you have to collect the disk space report over time. Then, create your report from that.

        Personally, I would store that data in a database, for example DBD::SQLite, and then create the reports from that database using Querylet. But you can get by without a relational database if you hardcode the reporting logic into your script.

A reply falls below the community's threshold of quality. You may see it by logging in.