If what you want is to get the available space on a specific disk volume from within a perl script, I'd do something like this:
my $targ_vol = "/"; my @df_output = `df -k $targ_vol`; # output should be two lines: # first line is column headings, second line is data my %df_data; if ( @df_output ) { my @headings = split( /\s+/, $df_output[0] ); my @data = split( /\s+/, $df_output[1] ); @df_data{@headings} = @data; } print "available on $targ_vol: $df_data{Avail}\n"; # (your version of df might use some string similar to but different f +rom "Avail")
You shouldn't have a problem if you're just looking at "/".

(update: if you're looking at some path other than "/", you need to be careful about knowing whether it's on some different file system, and figuring out whether that file system is currently mounted -- if it isn't, df will give you info about "/" instead. And God help you if it's mounted as NFS, and the NFS server has gone down...)

(update: BTW, when I try "df | egrep '/^'", nothing comes out, which is what I would expect; but if I do "df | egrep '/$'", I get the line that ends with a slash. That's what I don't understand about your usage in the OP -- I think it can't work as posted, unless your "egrep" is way different from mine...)


In reply to Re^4: disk space utilization by graff
in thread disk space utilization by ministry

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.