Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Unix disk space reports

by salvadors (Pilgrim)
on Dec 31, 2000 at 02:56 UTC ( #49030=note: print w/ replies, xml ) Need Help??

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?).


Comment on Re: Unix disk space reports
Select or Download Code
Re: Re: Unix disk space reports
by mr_leisure (Beadle) on Jan 02, 2001 at 13:58 UTC
    Well thanks for the arrogant reply there Tony. I guess the fact that this was my FIRST application of what I have learnt in Perl over the last month was lost on you big guy...
    if ($mr_leisure) { bow; }

      You're welcome.

      Although if you'd actually said "this is my first Perl script", or "please let me know what you think of this - I'm not really sure whether it's good or not", I might have replied differently than if you'd just offered it up as code for everyone, without any comments.

      I guess I'll note you down in my list of people who would rather everyone told them how great they were than offered constructive criticism?


        No, not really. That is not the type of person I am at all. Now without wanting to incur the wrath of our brethren by wasting nodes, allow me to draw your attention here. Thanks
        if ($mr_leisure) { bow; }
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://49030]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-11-27 23:21 GMT
Find Nodes?
    Voting Booth?

    My preferred Perl binaries come from:

    Results (190 votes), past polls