in reply to Net::Telnet::Cisco usage

You have some logic errors. ie every time through the loop you are resetting the content of @cmd_output. Try this:

my $cs = Net::Telnet::Cisco->new(Host => '123.123.123.123'); $cs->login('login', 'password'); my $DEBUG = 1; open( FI, $ciscomm_conf ) || die $!; my( @oks, @fails); while(<FI>) { # remove newline chomp; # skip blank or comment lines next if m/^\s*#/ or m/^\s*$/; my $cmd = $_; $DEBUG && print "Sending $cmd\n"; my @cmd_output = $cs->cmd( String => $cmd,Timeout =>60 ); if ( @cmd_output ) { $DEBUG && print "Recv: @cmd_output\n"; push @oks, [ $cmd, \@cmd_output ]; } else { $DEBUG && print "ERR: " . $cs->errmsg . "\n"; push @fails, [ $cmd, $cs->errmsg ]; } } close FI; $cs->close; use Data::Dumper; print "OK\n", Dumper(\@oks); print "Fail\n", Dumper(\@fails);

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Net::Telnet::Cisco usage
by chimni (Pilgrim) on Dec 22, 2003 at 08:21 UTC

    Hi Tachyon
    ++++++++ :)
    yes, an array is needed to store success output also.Oversight on my part.
    Two things i learnt from your post
    1 . Usage of next if rather than my ungainly if(pattern) && if(pattern)
    2 . The use of Data::dumper to print what i understand to be a "home made" data structure.
    Thanks for the tips
    regards,
    rajdeep.

      chomp() was the other thing you missed. It may or may not make a difference in this case but lines from files have newlines that you typically don't want.....

      cheers

      tachyon

      The other useful thing is:

      $DEBUG = 1; ..... $DEBUG && print "Well at least I got to here and I can get rid of this + msg by setting \$DEBUG = 0\n";

      cheers

      tachyon