NAME
PTools::SDF::CMD::BDF - Load '/bin/bdf' output into an PTools::SDF::IDX object
VERSION
This document describes version 0.04, released Apr, 2004.
SYNOPSIS
use PTools::SDF::CMD::BDF;
$bdfObj = new PTools::SDF::CMD::BDF;
or $bdfObj = new PTools::SDF::CMD::BDF(
$fsType, $matchCriteria, @fieldNames
);
After that, the $bdfObj acts just like any PTools::SDF::IDX object.
DESCRIPTION
Constructor
- new ( [ FStype ] [, MatchCriteria ] [, FieldNameList ] )
-
Collect output from the Unix /bin/bdf command and package it up in an PTools::SDF::IDX object for easy manipulation.
- FStype
-
When supplied the FStype parameter must be one of 'cdfs', 'hfs', 'nfs', 'vxfs' or 'all'. The default is to collect every file type in the output.
- MatchCriteria
-
Perl regular expressions can be used to limit the amount of data returned by the /bin/bdf command. This can be used in combination with the FStype parameter or not, as desired.
- FieldNameList
-
The default names for fields in objects of this class is
hostname filesystem kbytes used avail pctused mountedon
Use the FieldNameList parameter to supply alternate names. This is used simply to make client scripts more 'readable' to programmers. Just remember to supply names for all seven fields.
Example:
use PTools::SDF::CMD::BDF; $bdfObj = new PTools::SDF::CMD::BDF; or $fsType = "vxfs"; $matchCriteria = "\$mountpoint =~ m#ClearCase/newview/#"; (@fieldNames) = qw( hostname fsdev kbytes used avail pctused mountpoint ) $bdfObj = new PTools::SDF::CMD::BDF( $fsType, $matchCriteria, @fieldNames );
Note that in the above example, any FieldName used in the MatchCriteria field ('mountpoint') must match a name in the FieldNames list. Otherwise no entries will match, and no data will be returned in the resulting object.
Methods
A few additional public methods are defined here. See the various parent classes for examples of indexing and accessing the data contained in objects of this class.
- k2m ( Kbytes [, Format ] )
- kiloToMega ( Kbytes [, Format ] )
- k2g ( Kbytes [, Format ] )
- kiloToGiga ( Kbytes [, Format ] )
-
These methods provide a simple conversion from the Kbytes reported by the /bin/bdf command into either MegaBytes or GigaBytes
$kbytes = $bdfObj->param( $recNum, 'kbytes' ); # fetch total "kbytes" $mbytes = $bdfObj->k2m( $kbytes ); $gbytes = $bdfObj->k2g( $kbytes );
A Format string can be passed, and this is used in Perl's sprintf function to return a nicely formatted number. For example, to turn the total file system size attribute into a GigaByte fraction to one decimal place use the following.
$gbytes = $bdfObj->k2g( $kbytes, "%0.1f" );
- parseText ( Text [, MatchCriteria ] [, FieldNameList ] )
-
This method is used to translate output from the /bin/bdf program and populate the current object and can be called directly. The Text parameter is simple lines of text and the other parameters are the same as described in the new method, above.
Example:
$matchExp = "\$mountpoint =~ m#ClearCase/newview/#"; if ($ARGV[0] and $ARGV[0] eq "-") { # # If arg zero is a dash, read lines of text from # STDIN, assuming this is output from /bin/bdf # $bdfObj = new PTools::SDF::CMD::BDF( "no_bdf" ); while (defined ($line = <STDIN>)) { $text .= $line; } $bdfObj->parseText( $text, $matchExp, @fieldNames ); } else { # # Otherwise, any "vxfs" entries that match the expression # $bdfObj = new PTools::SDF::CMD::BDF( $fsType, $matchExp, @fieldNames ); }
Note that the above example passes a FSType of 'no_bdf' to the new method. This is used to instantiate an object without running any /bin/bdf process.
- parseUname ( MountPath [, Pattern [, Pattern ... ]] )
-
Given an arbitrary file system mount point, look for patterns indicating that a "uname" is associated with the file system.
If no user-defined "regular expression" Pattern(s)" then we will attempt to pull a $uname from the following default pattern space.
qw( ^/home/(.*)$ ^/nethome/(.*)$ ^/users/(.*)$ );
The various patterns are matched sequentially. The first time a match succeeds the value is returned and any subsequent patterns are not used.
$mount = $bdfObj->param( $recNum, 'mountedon' ); $uname = $bdfObj->parseUname( $mount );
In this example, if $mount equals '/home/janedoe', for example, then $uname will equal janedoe as the default pattern list, shown above, is used here.
INHERITANCE
This class inherits from the PTools::SDF::ARRAY and PTools::SDF::IDX classes. Additional methods are available via these and other parent classes.
SEE ALSO
See PTools::SDF::Overview, PTools::SDF::ARRAY, PTools::SDF::CSV, PTools::SDF::DB, PTools::SDF::DIR, PTools::SDF::DSET, PTools::SDF::File, PTools::SDF::IDX, PTools::SDF::INI, PTools::SDF::SDF, PTools::SDF::TAG PTools::SDF::Lock::Advisory, PTools::SDF::Sort::Bubble, PTools::SDF::Sort::Quick and PTools::SDF::Sort::Shell.
AUTHOR
Chris Cobb, <nospamplease@ccobb.net>
COPYRIGHT
Copyright (c) 2003-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.