My script is connecting to a cisco 2600 console server and attempting to enter commands. I can see in the input log that all commands are entered successfully and I see the results but nothing is printing to STDOUT or STDERR and I see command failed and pattern match timed out errors. Is this a problem with my regex? I've tried a bunch of different regular expressions with no luck so I stuck with the one from Net::Telnet::Cisco. My prompts look like the following:
blc6450vpt1>en Password: blc6450vpt1#conf t Enter configuration commands, one per line. End with CNTL/Z. blc6450vpt1(config)#interface ethernet 1 blc6450vpt1(config-if-eth)#
Here's a snippet of the test script:
#!/usr/bin/perl ## modules to use use strict; use warnings; use Net::Telnet; use Data::Dumper; #$|++; # ## establish some global variables my $HOSTNAME = "10.2.200.10"; my $HOSTPORT = "2033"; my $input_file = 'input.log'; my $output_file = 'output.log'; my $option_file = 'option.log'; my $dump_file = 'dump.log'; my $conn = new Net::Telnet ( Timeout => "3", Errmode => \&error_sub, #Errmode => "return", #Dump_Log => $dump_file, Input_log => $input_file, #Option_log => $option_file, #Output_log => $output_file, Output_record_separator => "", Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\) +)?\s?[\$#>]\s?(?:\(enable\))?\s*$)/' ); # open connection to host $HOSTNAME and port $HOSTPORT # and die if there is a problem unless ($conn->open(Host => $HOSTNAME, Port => $HOSTPORT)) { die "Error opening socket:: ".$conn->errmsg(); } print "Connected to ".$conn->host().", port ".$conn->port()."\n"; # Force the password prompt to be displayed by sending a ^M $conn->print(" "); $conn->waitfor('/Password:/'); $conn->print("password\n"); #Regex to match most IOS devices $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\( +enable\))?\s*$)/'); $conn->cmd("term length 0\n"); $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\( +enable\))?\s*$)/'); $conn->cmd("term width 120\n"); $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\( +enable\))?\s*$)/'); my @num = $conn->cmd(String => "show clock\n", Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)] +*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print Dumper(\@num); print STDERR Dumper(\@num); my @output = (); $conn->print("show version\n"); my (undef, $process_string) = $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(con +fig[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print $process_string . "\n"; print STDERR $process_string; print Dumper($process_string); sub error_sub{ my $error = shift; print "Made it to error method " . Dumper($error, \@_); }

Here is the output of the attempted test run:
[prompt]$./Net_Telnet_console.pl Connected to 10.2.200.10, port 2033 Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'command timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'command timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = []; Made it to error method $VAR1 = 'command timed-out'; $VAR2 = []; $VAR1 = []; Made it to error method $VAR1 = 'pattern match timed-out'; $VAR2 = [];

Here is what the input.log shows:
Test]$ cat input.log Password: blc6450vpt1>term length 0 blc6450vpt1>term width 120 blc6450vpt1>show clock *13:35:28.043 PST Sat Aug 21 2010 blc6450vpt1>show version ......don't need to paste the rest

In reply to Net::Telnet cmd results not printing to STDOUT by josh803316

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.