this is old and ugly but has been used daily for quite some time. the real version uses another method to get the needed passwords, i've removed that chunk for clarity.

#!/usr/bin/perl use strict; use warnings; $|++; sub usage { my $n = ($0 =~ s:.*/::, $0); return <<_EOU_; Usage: $n [-e] [-a] router [cmdfile [outfile [errfile]]] -e -- do enable. -a -- append to outfile and errfile. \$ cat >dothis sho inter lo0 sho inter gi3/2 ^D \$ rtrchat -e rtrname dothis interface Loopback0 .... \$ _EOU_ } use Getopt::Std; my %opt; getopts('ea',\%opt); my $rtr = shift @ARGV or die usage; my $if = shift @ARGV; my $of = shift @ARGV if $if; my $ef = shift @ARGV if $of; my $console = 'pass'; my $enable = 'pass'; #print "$rtr $if $of $ef @pw\n"; if ($if) { open(IF,"<$if") or die "open $if: $!"; } else { *IF = *STDIN; } my @ci = <IF>; close(IF); my $rw = $opt{a} ? '>>' : '>' ; chomp @ci; if ($of) { open(OF,"$rw$of") or die "open $of: $!"; } else { *OF = *STDOUT; } if ($ef) { open(EF,"$rw$ef") or die "open $ef: $!"; } else { *EF = *STDERR; } # while (<IF>) { print OF; print EF "foo $_" } use Net::Telnet::Cisco; my $c=Net::Telnet::Cisco->new(Host=>$rtr, Timeout => 45) or die"connect $rtr: $!"; $c->errmode( sub { print EF @_,"\n" } ); $c->login("nobody",$console) or die "login"; $c->enable($enable) or die "enable" if $opt{e}; $c->cmd("term len 0")or die "len"; foreach (@ci) { print OF $c->cmd($_); } $c->close;

In reply to Re: Net::Telnet::Cisco usage by zengargoyle
in thread Net::Telnet::Cisco usage by chimni

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.