in reply to Re: Can't get data from cisco router/switch when telnetting in via perl script.
in thread Can't get data from cisco router/switch when telnetting in via perl script.

I always receive a timeout error (command timed-out at TestTelnet.pl line 53) when I try the 'cmd' command. I've tested the telnet login and know it works. Assigning and running the command on the switch won't save data to my array.
  • Comment on Re^2: Can't get data from cisco router/switch when telnetting in via perl script.

Replies are listed 'Best First'.
Re^3: Can't get data from cisco router/switch when telnetting in via perl script.
by monarch (Priest) on Aug 21, 2007 at 09:47 UTC
    The Net::Telnet module must be configured to recognise the input prompt, otherwise it will not know when the last command completed.

    If you are receiving timeouts it is most likely the default prompt matching string is not matching your router's prompt.

    Please read the documentation for Net::Telnet. To make your life easier, specifically look deeper at the likes of:

    $t = new Net::Telnet (Timeout => 10, Prompt => '/bash\$ $/');

    Note that you'll have to change the Prompt regexp to something that matches your router's prompt.. if you provide examples of what your router's prompts look like someone can suggest a suitable regexp.

      I just wanted to add: the default prompt (in the documentation for Net::Telnet) is /[\$%#>] $/ (which probably doesn't match a typical IOS prompt).

      Note that there also exists a Net::Telnet::Cisco module if you don't want to go to the (relatively simple) trouble of configuring your own prompt regexp.

      monarch's comment is spot on. While I use the Net::Telnet::Cisco module I made a quick script just using Net::Telnet. Below is a script that logs into a 3750 switch and performs show clock. the switch's prompt is 3750G>. Without the prompt, the script simply times out.
      use Net::Telnet; # use the telnet module my $host = '3750g'; my $t = new Net::Telnet (Timeout => 10, Prompt => '/3750G\>/', ); $t->open($host); $t->login($user,$pass); @data = $t->cmd("show clock"); print "data is @data"; $t->close;
      Here is the output of the script: data is 19:21:11.575 UTC Tue Aug 21 2007 I hope you can add the Net::Telnet::Cisco module in the future. It greatly simplifies life if you have a bunch of these to keep track of.
Re^3: Can't get data from cisco router/switch when telnetting in via perl script.
by regexes (Hermit) on Aug 21, 2007 at 09:43 UTC
    Have you tried running the code with the debugger? (i.e. the -d command line switch?)

    Does the array even contain data?

    e.g
    DB<5> x @data
    What do you receive as output? A list of elements or empty array?

    regexes