#!/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 = ; 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 () { 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;