hey all,

I am working on some simple perl code to do the following:

1) Passed a device IP, the script should attempt to log into each device. If a timeout or any other error occurs, ignore the device and continue to attempt log ins to the other devices in the list.

I am using code similar to the following: (this works on a single device - for all devices that have telnet enabled without issue - so the actual telnet login script is good, but its the error catching i have issues with!)

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,

# Get any errors
$error = $telnet->errmsg;
if ($telnet->errmsg) { # continue with telnet stuff, else ignore device
else {
$telnet->waitfor('/login: $/i');
$telnet->waitfor('/password: $/i');
$telnet->waitfor('/\$ $/i');
$output = $telnet->waitfor('/\$ $/i');

#Do stuff with output for the device - this stuff is unimportant based on my error.

When i try running this with a list of 5 devices, 4 of which have telnet enabled, 1 that does not (all 4 that have it enabled are able to be logged into without issue via cli telnet) - i get an error that simple says 'Alarm Clock'. I have tried looking this up - and not sure what to think of it.

I have tried using eval {} tags around and still get the same issue. The code runs contiunously (well, not really continuously, but it sleeps for 5 minutes then tries everythign again, so crashing is not an option, i have to catch the error somehow)

Can anyone throw their two cents in and helps me out here? I appreciate it. If you need more info, let me know.

any ideas folks? need more info to answer or just a dumb question?

I don't have any experience with Telnet and can't reproduce your 'Alarm Clock'. Have you tried adding a print statement to print the $telnet->errmsg() when there is one?

# Get any errors
my $error = $telnet->errmsg;
if ($telnet->errmsg) { # continue with telnet stuff, else ignore device
    print $telnet->errmsg();# Add this line to examine errmsg
else {
# ... etc.

When I run your script with that line added the output is unknown remote host: DeviceIP of course because I have no device to telnet into, but I don't get an 'Alarm Clock' error and the script exits after printing the error. I don't see a problem if you have the script in a loop that is sleeping 5 minutes and retrying. You could print or log the errors or just ignore them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.