You probably want to pass the host/port in the open() method, otherwise when you call 'new' it will attempt to connect, and if it fails, it will just die.
Also, if you set Errmode to 'return', then you can get the error string using the errmsg() function.
What's the rest of the script look like? I tried the following code, and it works fine:
#!/usr/bin/perl -w
use strict;
use Net::Telnet;
my $HOST = 'my.server';
my $PORT = 22;
my $socket = new Net::Telnet (
Timeout => 30,
Dump_log => 'service-monitor.dumplog',
Input_log => 'service-monitor.inputlog'
Output_log => 'service-monitor.outputlog
Errmode => 'return',
) or die "new Net::Telnet: $!\n";
my $count = 0;
while(1) {
print "Opening socket number: ", ++$count, ".\n";
$socket->open(Host => $HOST, Port => $PORT);
if($socket->waitfor('/^SSH
$socket->close;
print "Got it.\n";
}
else {
print "waitfor failed: ".$socket->errmsg()."\n";
}
sleep(5);
}
Main Topics
Browse All Topics





by: stevefNYCPosted on 2005-12-14 at 07:17:55ID: 15482444
Well I figured out how to capture the error message using Errmode in the constructor, however now I have an issue with this segment of the code;
$/')) {
my $socket = new Net::Telnet ( Timeout => 45,
Dump_log => $dump_log,
Host => $host,
Input_log => $dump_log,
Output_log => $dump_log,
Port => 22,
Errmode => $error_handler,
);
my $count = 0;
while(1) {
sleep(60);
print "Opening socket number: ", ++$count, ".\n";
$socket->open;
if ($socket->waitfor('/^SSH.*
$socket->close;
next;
}
else {
mail() and die;
}
}
on the second iteration of the loop, it somehow always hits the else {} bracket, albeit ssh being responsive. I thought closing the socket might fix the issue ..