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,
Errmode=>'return');
$telnet->open('DeviceIP');
# Get any errors
$error = $telnet->errmsg;
if ($telnet->errmsg) { # continue with telnet stuff, else ignore device
}
else {
$telnet->waitfor('/login: $/i');
$telnet->print('test');
$telnet->waitfor('/password: $/i');
$telnet->print('test');
$telnet->waitfor('/\$ $/i');
$telnet->print('who');
$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.