Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::Telnet

Status
Not open for further replies.

Vuti

ISP
Jul 25, 2002
7
GB
My script telnets a router & does a traceroute on the device & then returns the output $response to a webpage. However when doing a traceroute to non reachable destinations, the trace continually times out until the (cisco) default of 30 icmp echos is completed, see below:

GSR-HSD-GW2#traceroute 194.117.xx.xx

Type escape sequence to abort.
Tracing the route to 194.117.xx.xx

1 194.117.xx.x 0 msec 208 msec 0 msec
2 19x.xx.xx.x 200 msec 204 msec 12 msec
3 * * *
4 * * *
<snip>
30 * * *
GSR-HSD-GW2#

My waitfor(String=> in this example is GSR-HSD-GW2# - but I obviously don't want to wait the full 2-3 mins until the failed trace has run it's course before $response has completed & the output can be printed to the html page.

My question is: can the waitfor string in Net::Telnet be expanded to cater for more then one variable ie. GSR-HSD-GW2# |&| * * *

Or is there an easier way to to do this that my dumb ass can't think of? (make the $response quit if more then 3 *'s are encountered - what code to use to do this?)

Script excerpt:

use Net::Telnet();
my $t = new Net::Telnet;
$t->errmode(&quot;return&quot;);
$t->open($router{$location});
$t->login (Name => &quot;$router_login{$location}&quot;, Password => &quot;$router_pass{$location}&quot;, Prompt => '/\#|&|\>/', Timeout =>60);

$t->print(&quot;trace $trace&quot;);
($response)=$t->waitfor(String=> &quot;$router_prompt{$location}&quot;, Timeout => 15);

@lines_trace=split(/\n/,$response);
 
Have you tried replacing the Timeout value of 60 with a variable and then use an if? e.g.

if router1 Timeout = 30, if router2 Timeout = 60 etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top