#!/usr/bin/perl -w
# $Id: report-client,v 1.1 2006/03/29 08:04:28 skoch Exp $
use strict;
use Socket;
my ($remote,$port, $iaddr, $paddr, $proto, $line);

$remote  = shift(@ARGV);
$port    = 4040;

if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
     die "No port" unless $port;
     $iaddr   = inet_aton($remote)               || die "no host: $remote";
     $paddr   = sockaddr_in($port, $iaddr);

     $proto   = getprotobyname('tcp');
     socket(SOCK, PF_INET, SOCK_STREAM, $proto)  || die "socket: $!";
     connect(SOCK, $paddr)    || die "connect: $!";
select(SOCK);$|=1;select(STDOUT);
for (my $x = 0; $x < scalar(@ARGV);$x++)
{
    print SOCK "$ARGV[$x] ";
}
print SOCK "\n\n";
my $out = '';
while (defined($line = <SOCK>)) 
{
    $out = $out.$line;
}
my $result = 1;
close (SOCK)            || die "close: $!";
if ($out =~ /command executed/i)
{
    $result = 0;
}
else
{
    chomp $out;
    print $out,"\n";
}
exit $result;

