Let me explain.
My script go on a text file that contain IP addresses. I have a subroutine that duty is to connect to a remote machine.
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);
}
I tried the first option and the script stoped the moment an error occured.
The secoond option didn't worked, when i tried to run the script i got a lot of error messages about not recognizing the $telnet.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 37.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 39.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 43.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 56.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 57.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 58.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 59.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 63.
Global symbol "$telnet" requires explicit package name at ./connect_telnet.pl line 7
Any suggestions??
Thanks!!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.