Hello Monks,
Forgive the title, I would welcome more descriptive titles.
I have a vendor application that requires that I telnet to the server/port to control certain functions. I want to automate some functions but seem to be running into some issues.
There are 2 commands I want to feed to the program, status and exit.
Interactivly this works fine. I type "status" and it lists data. I can type list any number of times. Once I type exit, the telnet session exits.
I was hoping to keep the session open and simply type status for as long as I need, then type exit. But instead I seem to have to establish a new session each time.
I would appreciate any pointers.
Code
use IO::Socket::INET;
my $port = 10405;
my $host = 'server';
my $socket = IO::Socket::INET->new(PeerAddr => "$host",
PeerPort => $port,
Proto => "tcp",
timeout => 3,
Type => SOCK_STREAM) || die "
+Could not establish connection : $!\n";
#$SIG{ALRM} = sub { print $socket "exit\n" };
my $header = <$socket>;
print $socket "status";
#alarm(1);
while(<$socket>) {
chomp;
print "$_\n";
}
print "out of loop\n";
However when I run it from the script below it hangs. I belive it is because I am waiting for input on my socket, but none ever comes. To get around this, I set an alarm for 1 second then print exit
In the current form, it hangs for ever. If I uncomment the alarm parts, it works fine.