in reply to Re: Problems using Filesys::DiskFree
in thread Problems using Filesys::DiskFree

Nope! It seems that I'm not the only one that can't get this to work! Funnily enough I have tried returning the output to a variable (List &/or Scalar) and they remain resolutely empty! This module must store the output somewhere and that's the real problem - where? Any ideas? The following code -
#!/usr/bin/perl -w
use Filesys::DiskFree;
$handle = new Filesys::DiskFree ;
my $count = 0 ;
$disc = '/dev/vx/dsk/var';
my $crap = $handle->device($disc) ;
print "\n\t$crap\n" ;
when run results in -

Use of uninitialized value in concatenation (.) or string at acc_filestore_monitor.pl line 8.

That would be because crap is empty. Trying the disks method returning the results (or so I thought) to an array produced the same error. I'm quite willing to accept that I can be somewhat dim at times but, not being familiar with methods etc to any great degree, I do think that the description of this module and it's use would leave someone with more knowledge on the subject scratching their heads! I'm probably going to use Filesys::Df to perform this function but I would like to get to the bottom of this as I don't like to be defeated in this fashion.
Cheers Ronnie "currently vanquished" Cruickshank
  • Comment on Re: Re: Problems using Filesys::DiskFree

Replies are listed 'Best First'.
Re: Re: Re: Problems using Filesys::DiskFree
by tachyon (Chancellor) on Mar 05, 2004 at 16:18 UTC

    This is vitually straight out of the docs. Having read the ten lines of synopsis you have to call it like this which as you see performs as desired. The issue is that the df() method need to be called (it calls df(1) and caches the results) so that most of the other methods have data to work with. When reading those docs substitute Filesys::DiskFree->method() with $handle->method() and you should have no issues:

    [root@devel3 root]# cat diskfree.pl #!/usr/bin/perl use Filesys::DiskFree; $handle = new Filesys::DiskFree; $handle->df(); my $device = $ARGV[0] || "/"; print "The $device device is ".$handle->device($device)."\n"; print "It has ".$handle->avail($device)." bytes available\n"; print "It has ".$handle->total($device)." bytes total\n"; print "It has ".$handle->used($device)." bytes used\n"; [root@devel3 root]# ./diskfree.pl The / device is /dev/sda3 It has 79425527808 bytes available It has 142137049088 bytes total It has 55491371008 bytes used [root@devel3 root]# ./diskfree.pl /boot The /boot device is /dev/sda1 It has 31190016 bytes available It has 47755264 bytes total It has 14099456 bytes used [root@devel3 root]# ./diskfree.pl /dev/sda1 The /dev/sda1 device is /dev/sda1 It has 31190016 bytes available It has 47755264 bytes total It has 14099456 bytes used [root@devel3 root]#

    cheers

    tachyon