3 =head2 NAME $RCSfile: FileSystem.pm,v $
5 Object oriented interface to filesystems
13 Andrew DeFaria <Andrew@ClearSCM.com>
21 Thu Dec 11 10:39:12 MST 2008
31 This module implements a FileSystem object.
33 $fs = new FileSystem ("hosta");
35 while ($fs->filesystem) {
36 display "Filesystem: $_";
37 display "\tSize:\t$fs{$_}->size";
38 display "\tUsed:$fs{$_}->used";
39 display "\tFree:$fs{$_}->free";
40 display "\tUsed %:$fs{$_}->usedPct";
41 display "\tMounted on:$fs{$_}->mount";
46 Filesystem creates a filesystem object that encapsulates information
47 about the file system as a whole.
51 The following routines are exported:
73 Construct a new Filesystem object. The following OO style arguments are
78 =for html <blockquote>
86 =for html <blockquote>
90 =item Filesystem object
94 =for html </blockquote>
99 my ($class, $system, $ostype, $username, $password, $prompt, $shellstyle) = @_;
101 # Set prompt if not passed in
102 $prompt ||= $Rexec::default_prompt;
104 # Connect to remote machine
105 my $remote = new Rexec (
107 username => $username,
108 password => $password,
110 shellstyle => $shellstyle,
114 error "Unable to connect to $system";
121 # Sun is so braindead!
122 if ($ostype eq "Unix") {
123 foreach ("ufs", "vxfs") {
124 my $cmd = "/usr/bin/df -k -F $_";
126 my @unixfs = $remote->exec ($cmd);
128 if ($remote->status != 0) {
129 error ("Unable to determine fsinfo on $system ($cmd)\n" . join ("\n", @fs));;
136 for (my $i = 0; $i < scalar @unixfs; $i++) {
137 my (%fsinfo, $firstField);
139 # Trim leading and trailing spaces
140 $unixfs[$i] =~ s/^\s+//;
141 $unixfs[$i] =~ s/\s+$//;
143 my @fields = split /\s+/, $unixfs[$i];
145 if (scalar @fields == 1) {
146 $fsinfo{fs} = $fields[0];
150 # Trim leading and trailing spaces
151 $unixfs[$i] =~ s/^\s+//;
152 $unixfs[$i] =~ s/\s+$//;
154 @fields = split /\s+/, $unixfs[$i];;
156 $fsinfo{fs} = $fields[0];
160 $fsinfo{size} = $fields[$firstField] * 1024;
161 $fsinfo{used} = $fields[$firstField + 1] * 1024;
162 $fsinfo{free} = $fields[$firstField + 2] * 1024;
163 $fsinfo{reserve} = $fsinfo{size} - $fsinfo{used} - $fsinfo{free};
165 $fs{$fields[$firstField + 4]} = \%fsinfo;
168 } elsif ($ostype eq "Linux") {
170 my $cmd = "/bin/df --block-size=1 -t $_";
172 my @linuxfs = $remote->exec ($cmd);
174 if ($remote->status != 0) {
175 error ("Unable to determine fsinfo on $system ($cmd)\n" . join ("\n", @fs));;
186 $fsinfo{fs} = $fields[0];
187 $fsinfo{size} = $fields[1];
188 $fsinfo{used} = $fields[2];
189 $fsinfo{free} = $fields[3];
190 $fsinfo{reserve} = $fsinfo{size} - $fsinfo{used} - $fsinfo{free};
192 $fs{$fields[5]} = \%fsinfo;
196 error "Can't handle $ostype", 1;
206 Returns an array of mount points
210 =for html <blockquote>
220 =for html </blockquote>
224 =for html <blockquote>
228 =item Array of mount points
232 =for html </blockquote>
244 =head3 getFSInfo ($mount)
246 Returns a hash of filesystem info for a mount point
250 =for html <blockquote>
254 =item $mount: Mount point
260 =for html </blockquote>
264 =for html <blockquote>
268 =item Hash of filesystem info
272 =for html </blockquote>
277 my ($self, $mount) = @_;
279 return %{$self->{$mount}};
286 =head2 CONFIGURATION AND ENVIRONMENT
296 =head2 INCOMPATABILITIES
300 =head2 BUGS AND LIMITATIONS
302 There are no known bugs in this module.
304 Please report problems to Andrew DeFaria (Andrew@ClearSCM.com).
306 =head2 LICENSE AND COPYRIGHT
308 This Perl Module is freely available; you can redistribute it and/or
309 modify it under the terms of the GNU General Public License as
310 published by the Free Software Foundation; either version 2 of the
311 License, or (at your option) any later version.
313 This Perl Module is distributed in the hope that it will be useful,
314 but WITHOUT ANY WARRANTY; without even the implied warranty of
315 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
316 General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
319 You should have received a copy of the GNU General Public License
320 along with this Perl Module; if not, write to the Free Software Foundation,
321 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.