Here's something you might find useful. It's almost straight out of the Ram book, adapted to collect uptimes from little Perl uptime servers.
Here's the server that runs on each of the reporting machines...
#! /usr/bin/perl -w
#
# loadserv.pl
#
use strict ;
use warnings ;
use IO::Socket ;
my $server_port = 2048 ;
my $server = IO::Socket::INET->new( LocalPort => $server_port,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10 )
or die "Couldn't be a TCP server on port $server_port: $@\n" ;
while ( my $client = $server->accept() )
{
print $client `uptime` ;
}
close( $server ) ;
...and here's the client that collects the uptime information from the various servers.
#! /usr/bin/perl -w
#
# loadclient.pl
#
use strict ;
use warnings ;
use IO::Socket ;
my @remote_hosts = (
{ addr => '127.0.0.1' },
{ addr => '123.123.123.123' }
) ;
my $remote_port = 2048 ;
foreach my $host ( @remote_hosts )
{
my $socket = IO::Socket::INET->new( PeerAddr => $host->{ addr },
PeerPort => $remote_port,
Proto => 'tcp',
Type => SOCK_STREAM )
or die "Couldn't connect to $host->{ addr }:$remote_port: $@\n"
+;
$host->{ uptime } = <$socket> ;
}
# The anonymous hashes in @remote_hosts now also contain
# the uptimes of the servers listed.
This worked for me when I ran the server on my local machine as well as a remote machine. Hope this helps. Also, I'd really appreciate knowing what people think of this approach.
_______________
D
a
m
n
D
i
r
t
y
A
p
e
Home Node
|
Email
|