Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w # errdis.pl # pod at tail use strict; use Net::Telnet::Cisco; use Term::ReadKey; use Term::ReadLine; my %parm = ( tntimeout => 30, pwtimeout => 60, errmode => 'return', ); my %file = ( in => 'errdis.in', tmp0 => 'errdis.tmp0', tmp1 => 'errdis.tmp1', out => 'errdis.out', ); my @tmpfiles = qw( $file{tmp0} $file{tmp1} ); my @commands = ( 'set leng 0', # CatOS no '--More--' scrolling 'sho port st', # meat n' potatos ); my @keeplines = ( # lines of text to be kept 'sho port st', 'errdis', # 'auto', # 'connected', # ' 10 ', # ' 100 ', ); ###################################################################### +#### Usage() unless ((@ARGV) or (-s $file{in} && -T_)); # $file{tmp1} must be present or errors if first device unreachable open (TMP1, ">$file{tmp1}") or die "Error opening $file{tmp1} WO: $!"; close (TMP1) or die "Error closing $file{tmp1}: $1"; ###################################################################### +#### # noecho *before* prompting for password - isotope # don't need privilaged mode for 'sho port st' # Win32 - "Non-blocking ReadLine is not supported on this architecture +" ReadMode('noecho'); print "\n", " Prompting for password\n", " (*not* echoed to screen nor written to disk)\n\n", ' Enter password: '; my $pass; if ($^O eq 'MSWin32') { chomp ($pass = <STDIN>); } else { $pass = ReadLine($parm{pwtimeout}); } ReadMode('restore'); unless (defined($pass)) { print "\n\nSorry, you waited too long to enter the password.\n\n"; exit; } ###################################################################### +#### unless (@ARGV) { print "\n Using $file{in} for input\n"; @ARGV = $file{in}; chomp (@ARGV = <>); } ###################################################################### +#### print "\n Starting port status check, shouldn't take long...\n"; for my $cisco (@ARGV) { if (my $cs=Net::Telnet::Cisco->new( host => $cisco, timeout => $parm{tntimeout}, errmode => $parm{errmode}, input_log => $file{tmp0}, ) ) { $cs->login('',$pass); # vty login print ' ', $cs->last_prompt, ' '; # print to console for(@commands) { my @output = $cs->cmd($_); } print $cs->last_prompt, "\n"; # print to console $cs->close; # exit session open (TMP0, "<$file{tmp0}") or die "Error opening $file{tmp0} RO: $!"; open (TMP1, ">>$file{tmp1}") or die "Error opening $file{tmp1} for append: $!"; while (<TMP0>) { print TMP1 $_; } close (TMP0) or die "Error closing $file{tmp0}: $ +!"; close (TMP1) or die "Error closing $file{tmp1}: $ +!"; } else { warn "Error connecting to $cisco\n"; } # if telnet connec +t fail } unlink ($file{tmp0}) or die "Error unlinking $file{tmp0}: + $!"; print " Finished port status check.\n"; ###################################################################### +#### print " Extracting lines of interest...\n"; open (TMP1, "<$file{tmp1}") or die "Error opening $file{tmp1} RO: $!" +; open (OUT, ">$file{out}") or die "Error opening $file{out} WO: $!"; while (<TMP1>) { foreach my $keep(@keeplines) { if (/$keep/i) { print OUT $_; print; } } } close (TMP1) or die "Error closing $file{tmp1}: $!"; unlink ($file{tmp1}) or die "Error unlinking $file{tmp1}: $!"; close (OUT) or die "Error closing $file{out}: $!"; ###################################################################### +#### print " Finished parsing results.\n", " Output at $file{out}\n\n\a"; if ($^O eq 'MSWin32') { print " <enter> to exit."; (<STDIN>); exit; } ###################################################################### +#### sub Usage { print <<EOF; D'oh! You didn't specify any target device(s) on command-line or at +$file{in}. If you want to try again, use the following syntax: errdis.pl switch1 switch2 switch3 will query the 3 named (or numbered) switches for port status errdis.pl with no arguments will read $file{in} for list of switches to quer +y. $file{in} would be a text file that looks like this: switch1 switch2 switch3 ASCII text file One IP address or DNS name per line FQDN if targets in different DNS domain No leading/trailing spaces No blank lines Net::Telnet::Cisco $Net::Telnet::Cisco::VERSION Net::Telnet $Net::Telnet::VERSION Term::ReadKey $Term::ReadKey::VERSION Perl $] OS $^O Program $0 EOF exit; # exit instead of die, so no error to cons +ole } ###################################################################### +#### sub Pause { print "<enter> to continue, ctrl-C to quit.\n"; (<STDIN>); } ###################################################################### +#### =head1 Name errdis.pl =head1 Summary Report on 'errdisabled' ports at Cisco CatOS LAN switch(es). =head1 Usage errdis.pl switch1 switch2 switch3 will query the 3 named (or numbered) switches for port status errdis.pl with no arguments will read $file{in} for list of switches to quer +y. $file{in} would be a text file that looks like this: switch1 switch2 switch3 ASCII text file One IP address or DNS name per line FQDN if targets in different DNS domain No leading/trailing spaces No blank lines =head1 Tested with: Perl 5.00504 Debian 2.2r3 ActivePerl 5.6.1.626 Win2kPro against: Cisco Catalyst 6000, 5000, 4000, 2948g =head1 Updated 2001-05-07 16:00 List contents of outfile to console. 2001-05-04 10:55 Minor format tweaks. 2001-05-03 17:30 Initial working code (started from existing cdp-n.pl). Posted to PerlMonks. =head1 ToDos Prompt for (or accept switches using GetOpt::Long) (errdis|auto|connected| 10 | 100 ). Debug non-fatal error only seen on Win32: Argument "" isn't numeric in number gt (>> at Telnet.pm line 2569, +<STDIN> line 1. Use File::Slurp to append log (avoid race condition). Use File::Temp instead of multiple temp files. =head1 Author ybiC =cut

In reply to (code) Cisco errdisable (no password timeout if Win32) by ybiC

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2015-07-07 01:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (86 votes), past polls