I'm using Perl's Net::Telnet module to connect to a server and wait for a specific command prompt. However, I'm facing an issue where the waitfor method seems to get stuck indefinitely, even though I've specified a timeout. Here's the complete script that reproduces the problem:
use Net::Telnet;
# Replace with actual host and port
my $host = 'your_host_here';
my $port = 'your_port_here';
my $attempt_timeout = 15; # Adjust as needed
my $t = Net::Telnet->new(Timeout => 30);
$t->errmode('return');
# Attempt to open a Telnet session
eval {
$t->open(Host => $host, Port => $port);
};
if ($@) {
die "Failed to connect: $@\n";
}
# Waiting for the command prompt - this is where it gets stuck
eval {
$t->waitfor(Match => '/Command:.*$/', Timeout => $attempt_timeout);
};
if ($@) {
die "waitfor method failed: $@\n";
} else {
print "Command prompt received successfully.\n";
}
# Closing the session
$t->close();
When I run this script, it doesn't time out as expected at the waitfor step. Here are some details:
- The host and port are correctly set (verified).
- The regular expression in Match seems correct.
- Network connectivity doesn't appear to be an issue.
I'm curious as to why the timeout isn't working. Is this a known issue with Net::Telnet, or am I missing something in the implementation? Any help or suggestions on how to troubleshoot this further would be greatly appreciated.