Skip to content

Instantly share code, notes, and snippets.

@walf443
Created June 3, 2010 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walf443/423930 to your computer and use it in GitHub Desktop.
Save walf443/423930 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
use Getopt::Long;
my $port = 7003;
my $host = '127.0.0.1';
my $timeout = 10;
GetOptions(
'port=i' => \$port,
'host=s' => \$host,
'timeout=i' => \$timeout,
);
my $cmd = join q{ }, @ARGV;
my $interval_sec = 1;
print "HOST: $host\n";
print "PORT: $port\n";
print "CMD: $cmd\n";
while (1) {
print "\033[2J"; # flush screen
my $sock = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Timeout => $timeout,
) or die "cannot connect to $host:$port";
$sock->autoflush(1);
$sock->write($cmd . "\r\n");
my $out;
INNER: while ( defined ( my $line = <$sock> ) ) {
chomp $line;
if ( $line eq "." ) {
last INNER;
}
$out .= "$line\n";
}
print $out;
$sock->close;
sleep($interval_sec);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment