Presumably some chap has written a module that'll do what you need, but I don't know of one. If you can do system("df"), though, why not? (After all, Perl is good at parsing this kind of stuff.)

By "the two line junk," do you mean the header line or the line wrapping/splitting when the device name is too long?

Filesystem 1k-blocks Used Available Use% Mounted on /dev/sdb2 614208 522868 59612 90% / /dev/sdb3 614660 472372 110560 82% /usr /devfs/scsi/host0/bus0/target8/lun0/part6 711508 376520 298844 56% /build /devfs/scsi/host0/bus0/target8/lun0/part7 711508 574500 100864 86% /arc/1

My df (fileutils 4.1) takes a -P (a.k.a. POSIXLY_CORRECT) which forces each record to be on the same line. Uglier for humans; prettier for Perl. But in case yours doesn't:

# capacity($mountpoint) # # Returns the capacity (in 1024-byte units) of the # filesystem at $mountpoint. # sub capacity { my ($mp) = @_; my ($head, $line, $extra) = `df -kl $mp`; $line .= $extra if defined $extra; return (split ' ', $line)[1]; }

Before using this function, be sure to consider: security ($mp is passed to the shell), error handling, efficiency (you will have to spawn a subshell for every filesystem), and portability (not every OS has df).


In reply to Re: Calculating Mount Point Capacity by TilRMan
in thread Calculating Mount Point Capacity by St. Catharine

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.