Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 rodolico 1
#! /usr/bin/perl -w
2
 
3
# gets information on disks and partitions. Returns them as a hash
4
# uses standard df -kT and parses the output
5
# skips anything that does not have a device with /dev in it
6
# assumes the structure of the output is:
7
# device fstype size usedSpace availableSpace percentSpace mountPoint
8
# however, the output can sometimes wrap to multi lines, especially if the 
9
# device is long. So, we will replace all newlines with spaces, then 
10
# remove space duplications, then split on spaces and process each item in
11
# turn.
12
# NOTE: this will totally break if you have spaces in your mount point
13
 
14
BEGIN {
15
   push @INC, shift;
16
}
17
 
18
use library;
19
 
20
my $command = &validCommandOnSystem('df');
21
 
22
exit 1 unless $command;
23
 
24
my $CATEGORY = 'diskinfo';
25
 
26
# process physical partitions
27
my $temp = qx/df -kT/; # execute the system command df, returned values in kilobytes, showing file system types
28
@temp = split("\n", $temp ); # get array of lines
29
shift @temp; # get rid of the first line . . . it is nothing but header info
30
$temp = join( ' ', @temp ); # rejoin everything back with spaces
31
$temp =~ s/ +/ /gi; # remove all duplicate spaces
32
@temp = split( ' ', $temp ); # turn it back into an array of space separated values
33
while (@temp) {
34
   my $device = shift @temp; # get the device name
35
   my $output = '';
36
   $output .=  "$CATEGORY\t$device\tfstype\t" . (shift @temp) . "\n"; # next is fs type
37
   $output .=  "$CATEGORY\t$device\tsize\t" . (shift @temp) . "\n"; # total partition size, in k
38
   $output .=  "$CATEGORY\t$device\tused\t" . (shift @temp) . "\n"; # disk usage, in k
39
   shift @temp; # $available, not recorded
40
   shift @temp; # $percent, not recorded
41
   $output .=  "$CATEGORY\t$device\tmount\t" . (shift @temp) . "\n"; # mount point
42
   # now, if it is a /dev device, we add it to the diskInfo hash
43
   print $output if $device =~ m/\/dev/;
44
}