in reply to Re: Trying to capture error message using telnet::net
in thread Trying to capture error message using telnet::net
I use a while loop that each time call the subroutine to connect to a remote machine.
this function suppose to go on all the file with the IP addresses. but when an error occurs during the connection ( No ping, console port is occupied, etc) the script stops.
I want the script to generate an error lets say "The server is unreacable" each time it encounter an error, and continue to the outher IP's.
sub connect { my ($console_server,$console_port) = @_; my $telnet = new Net::Telnet ( Timeout=>10,Port => $console_po +rt ,Errmode=>'return'); $telnet->open("$console_server"); if ($telnet->errmsg){ print "errmsg: " . $telnet->errmsg . "\n"; } else { print"success\n"; } print ("loginig in...\n"); $telnet->print('user'); $telnet->waitfor('/password: $/i'); $telnet->print('password'); $telnet->waitfor('/# ?$/i'); print ("exiting...\n"); $telnet->print('exit'); } } while (<DATA>) { my $line = $_; print "trying to connect to console server $console_server_tem +p port $console_port_temp \n"; &connect($console_server_temp,$console_port_temp); }
Any suggestions?? Thanks!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Trying to capture error message using telnet::net
by Anonymous Monk on Mar 04, 2009 at 09:31 UTC |