#!/usr/local/bin/perl -w
#
# Silly program which shows using this module
#
use strict;
use Filesys::DiskFree;
# Create a new handle
my $df = new Filesys::DiskFree;
# Set the modes
$df->set('-mode'=>'blocks');
$df->set('-format'=>'solaris');
# Remember what format we're using
print $df->set('format'),"\n";
# Load a scalar with the right values.
my $line= <<EOL;
/dev/hdc1 366312 345605 1788 99% /home
/dev/hdd1 366312 345605 1788 99% /usr
EOL
# And load the scalar into the class
$df->load($line);
# Some prints of info
print $df->device('/dev/hdc1')." is mounted on ".$df->mount('/dev/hdc1')."\n";
$df = new Filesys::DiskFree;
$df->set('-mode'=>'blocks');
$df->set('-format'=>'bsdos');
$line= <<EOL;
Filesystem 512-blocks Used Avail Capacity iused ifree %iused Mounted on
/dev/sd0a 396670 191816 185020 51% 1611 48307 3% /
/dev/sd0h 6816728 2251342 4224548 35% 12738 840380 1% /home
EOL
# And load the scalar into the class
$df->load($line);
print $df->device('/home')." is mounted on ".$df->mount('/home')."\n";
# Start again, create another new handle
$df=new Filesys::DiskFree;
# This time we're using a file handle. This is a silly example,
# because you could do the same thing with just the df() method,
# but you could use rsh or some similar method to do this on a
# remote machine
my $cmd=$df->command();
open(DF,"$cmd|") or die "Cannot $cmd $!\n";
$df->load(\*DF);
close(DF) or die "Cannot $cmd $! $?\n";
# Now output the disks
my @disks=$df->disks();
print join(" ",@disks);
print "\n";
# Finally, output the # of free inodes on /
$df=new Filesys::DiskFree;
$df->set('-mode'=>'inodes');
$df->df();
print "Disk ".$df->device('/')." has ",$df->avail('/')," inodes available\n";