yea tried to understand the code before i used it think i understand it. here is what i plugged it into.. it just a simpole script that uses mobile agents to relocate to another machine then run the code in do_it on that machine and returns a scalar containg the contents of df -Tm
these are then stored in a hash this is done for a couple of machines then the contents of the hash must be sorted to display a ranked listing of the machines with the most space available
#! /usr/bin/perl -w
#
# drivespace
#
use strict;
use Mobile::Executive;
my %space;
######################################################################
+######################################################
sub do_it
{
return scalar `df -Tm`;
}
######################################################################
+#######################################################
relocate( 'xxx.xxx.xxx.xxx', 2001 );
$space{ 'xxx.xxx.xxx.xxx' } = do_it;
relocate( 'xxx.xxx.xxx.xxx', 2001 );
$space{ 'xxx.xxx.xxx.xxx'} = do_it;
#relocate( 'xxx.xxx.xxx.xxx', 2001 );
#$space { 'xxx.xxx.xxx.xxx'}= do_it;
#relocate( 'xxx.xxx.xxx.xxx', 2001 );
#$space = { 'xxx.xxx.xxx.xxx'}do_it;
#relocate( 'xxx.xxx.xxx.xxx', 2001 );
#$space = { 'xxx.xxx.xxx.xxx'}do_it;
relocate( 'xxx.xxx.xxx.xxx', 2001 );
my $counter = 1;
my @out;
my @lines;
my $disk_used = 0;
my $free = 0;
print "host:volume available(MB) %free\n";
foreach my $host (keys %space)
{
$_ = $space{$host};
@lines = map {
/(\/\w+\/\w+)\s+\w+\s+\d+\s+\d+\s+(\d+)\s+(\d+)%/;
{
volume => $1,
available => $2,
free => 100 - $3,
}
}split /\n/,$space{$host};
#This is the sorting line!
@lines = sort { $b->{available} <=> $a->{available} } @lines;
push @out, "$host:$_->{volume} $_->{available} $_->{free
+}%" for @lines;
}
Edited by Chady -- removed real IPs |