<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix"><font size="-1">Hi all.<br>
<br>
Bellow what I'have done. It's working for me for TOR model and
BladeCenter/Purflex switches :<br>
<br>
add in rancid-fe :<br>
'ibmbnt' => 'bntrancid',<br>
<br>
<br>
new file in $rancid-home/bin : bntrancid with 755<br>
<br>
<br>
#! /usr/bin/perl<br>
##<br>
## $Id: rancid.in 2272 2011-01-10 20:01:58Z heas $<br>
##<br>
## rancid 2.3.6<br>
## Copyright (c) 1997-2009 by Terrapin Communications, Inc.<br>
## All rights reserved.<br>
##<br>
## This code is derived from software contributed to and
maintained by<br>
## Terrapin Communications, Inc. by Henry Kilmer, John Heasley,
Andrew Partan,<br>
## Pete Whiting, Austin Schutz, and Andrew Fort.<br>
##<br>
## Redistribution and use in source and binary forms, with or
without<br>
## modification, are permitted provided that the following
conditions<br>
## are met:<br>
## 1. Redistributions of source code must retain the above
copyright<br>
## notice, this list of conditions and the following
disclaimer.<br>
## 2. Redistributions in binary form must reproduce the above
copyright<br>
## notice, this list of conditions and the following
disclaimer in the<br>
## documentation and/or other materials provided with the
distribution.<br>
## 3. All advertising materials mentioning features or use of
this software<br>
## must display the following acknowledgement:<br>
## This product includes software developed by Terrapin
Communications,<br>
## Inc. and its contributors for RANCID.<br>
## 4. Neither the name of Terrapin Communications, Inc. nor the
names of its<br>
## contributors may be used to endorse or promote products
derived from<br>
## this software without specific prior written permission.<br>
## 5. It is requested that non-binding fixes and modifications
be contributed<br>
## back to Terrapin Communications, Inc.<br>
##<br>
## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC.
AND CONTRIBUTORS<br>
## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED<br>
## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR<br>
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COMPANY OR
CONTRIBUTORS<br>
## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR<br>
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF<br>
## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS<br>
## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN<br>
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE)<br>
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE<br>
## POSSIBILITY OF SUCH DAMAGE.<br>
#<br>
# RANCID - Really Awesome New Cisco confIg Differ<br>
#<br>
# usage: rancid [-dV] [-l] [-f filename | hostname]<br>
#<br>
use Getopt::Std;<br>
getopts('dflV');<br>
if ($opt_V) {<br>
print "rancid 2.3.6\n";<br>
exit(0);<br>
}<br>
$log = $opt_l;<br>
$debug = $opt_d;<br>
$file = $opt_f;<br>
$host = $ARGV[0];<br>
$proc = "";<br>
$ios = "IOS";<br>
$clean_run = 0;<br>
$found_end = 0;<br>
$found_version = 0;<br>
$found_env = 0;<br>
$found_diag = 0;<br>
$timeo = 90; # bntlogin timeout in seconds<br>
<br>
my(@commandtable, %commands, @commands);# command lists<br>
my($aclsort) = ("ipsort"); # ACL sorting mode<br>
my($config_register); # configuration register value<br>
my($filter_commstr); # SNMP community string
filtering<br>
my($filter_pwds); # password filtering mode<br>
<br>
# This routine is used to print out the router configuration<br>
sub ProcessHistory {<br>
my($new_hist_tag,$new_command,$command_string,@string) =
(@_);<br>
if ((($new_hist_tag ne $hist_tag) || ($new_command ne
$command))<br>
&& scalar(%history)) {<br>
print eval "$command \%history";<br>
undef %history;<br>
}<br>
if (($new_hist_tag) && ($new_command) &&
($command_string)) {<br>
if ($history{$command_string}) {<br>
$history{$command_string} =
"$history{$command_string}@string";<br>
} else {<br>
$history{$command_string} = "@string";<br>
}<br>
} elsif (($new_hist_tag) && ($new_command)) {<br>
$history{++$#history} = "@string";<br>
} else {<br>
print "@string";<br>
}<br>
$hist_tag = $new_hist_tag;<br>
$command = $new_command;<br>
1;<br>
}<br>
<br>
sub numerically { $a <=> $b; }<br>
<br>
# This is a sort routine that will sort numerically on the<br>
# keys of a hash as if it were a normal array.<br>
sub keynsort {<br>
local(%lines) = @_;<br>
local($i) = 0;<br>
local(@sorted_lines);<br>
foreach $key (sort numerically keys(%lines)) {<br>
$sorted_lines[$i] = $lines{$key};<br>
$i++;<br>
}<br>
@sorted_lines;<br>
}<br>
<br>
# This is a sort routine that will sort on the<br>
# keys of a hash as if it were a normal array.<br>
sub keysort {<br>
local(%lines) = @_;<br>
local($i) = 0;<br>
local(@sorted_lines);<br>
foreach $key (sort keys(%lines)) {<br>
$sorted_lines[$i] = $lines{$key};<br>
$i++;<br>
}<br>
@sorted_lines;<br>
}<br>
<br>
# This is a sort routine that will sort on the<br>
# values of a hash as if it were a normal array.<br>
sub valsort{<br>
local(%lines) = @_;<br>
local($i) = 0;<br>
local(@sorted_lines);<br>
foreach $key (sort values %lines) {<br>
$sorted_lines[$i] = $key;<br>
$i++;<br>
}<br>
@sorted_lines;<br>
}<br>
<br>
# This is a numerical sort routine (ascending).<br>
sub numsort {<br>
local(%lines) = @_;<br>
local($i) = 0;<br>
local(@sorted_lines);<br>
foreach $num (sort {$a <=> $b} keys %lines) {<br>
$sorted_lines[$i] = $lines{$num};<br>
$i++;<br>
}<br>
@sorted_lines;<br>
}<br>
<br>
# This is a sort routine that will sort on the<br>
# ip address when the ip address is anywhere in<br>
# the strings.<br>
sub ipsort {<br>
local(%lines) = @_;<br>
local($i) = 0;<br>
local(@sorted_lines);<br>
foreach $addr (sort sortbyipaddr keys %lines) {<br>
$sorted_lines[$i] = $lines{$addr};<br>
$i++;<br>
}<br>
@sorted_lines;<br>
}<br>
<br>
# These two routines will sort based upon IP addresses<br>
sub ipaddrval {<br>
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);<br>
$a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));<br>
}<br>
sub sortbyipaddr {<br>
&ipaddrval($a) <=> &ipaddrval($b);<br>
}<br>
<br>
# This routine parses "show version"<br>
sub ShowVersion {<br>
print STDERR " In ShowVersion: $_" if ($debug);<br>
my($slaveslot);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
if (/^$prompt/) { $found_version = 1; last};<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(0) if ($found_version); # Only do this routine
once<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^Slave in slot (\d+) is running/) {<br>
$slave = " Slave:";<br>
$slaveslot = ", slot $1";<br>
next;<br>
}<br>
if (/cisco ios .* IOS-XE/i) { $ios = "XE"; }<br>
if (/^Application and Content Networking .*Software/) {
$type = "CE"; }<br>
# treat the ACE like the Content Engines for matching
endofconfig<br>
if (/^Cisco Application Control Software/) { $type = "CE"; }<br>
if (/^Cisco Storage Area Networking Operating System/) {
$type = "SAN";}<br>
if (/^Cisco Nexus Operating System/) { $type = "NXOS";}<br>
/^Application and Content Networking Software Release /i
&&<br>
ProcessHistory("COMMENTS","keysort","F1", "!Image: $_")
&& next;<br>
/^Cisco Secure PIX /i &&<br>
ProcessHistory("COMMENTS","keysort","F1", "!Image: $_")
&& next;<br>
# ASA "time-based licenses" - eg: bot-net<br>
/^This (PIX|platform) has a time-based license that will
expire in\s+(\d{2,})\s+day.*$/ &&<br>
ProcessHistory("COMMENTS","keysort","D1",<br>
"!This $1 has a time-based license\n") &&
next;<br>
# PIX 6 fail-over license, as in "This PIX has an
Unrestricted (UR)<br>
# license." PIX 7 as "his platform has ..."<br>
/^This (PIX|platform) has an?\s+(.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","D1", "!$_")
&& next;<br>
/^(Cisco )?IOS .* Software,? \(([A-Za-z0-9_-]*)\),
.*Version\s+(.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","F1",<br>
"!Image:$slave Software: $2, $3\n") && next;<br>
/^([A-Za-z-0-9_]*) Synced to mainline version: (.*)$/
&&<br>
ProcessHistory("COMMENTS","keysort","F2",<br>
"!Image:$slave $1 Synced to mainline version: $2\n")
&& next;<br>
/^Compiled (.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","F3",<br>
"!Image:$slave Compiled: $1\n") && next;<br>
/^ROM: (IOS \S+ )?(System )?Bootstrap.*(Version.*)$/
&&<br>
ProcessHistory("COMMENTS","keysort","G1",<br>
"!ROM Bootstrap: $3\n") && next;<br>
if (/^Hardware:\s+(.*), (.* RAM), CPU (.*)$/) {<br>
ProcessHistory("COMMENTS","keysort","A1",<br>
"!Chassis type: $1 - a PIX\n");<br>
ProcessHistory("COMMENTS","keysort","A2",<br>
"!CPU: $3\n");<br>
ProcessHistory("COMMENTS","keysort","B1", "!Memory:
$2\n");<br>
}<br>
/^serial number:\s+(.*)$/i &&<br>
ProcessHistory("COMMENTS","keysort","C1", "!Serial
Number: $1") &&<br>
next;<br>
# More PIX stuff<br>
/^Encryption hardware device\s+:\s+(.*)/ &&<br>
ProcessHistory("COMMENTS","keysort","A3", "!Encryption:
$1\n") &&<br>
next;<br>
/^running activation key\s*:\s+(.*)/i &&<br>
ProcessHistory("COMMENTS","keysort","D2", "!Key: $1\n")
&&<br>
next;<br>
# Flash on the PIX or FWSM (FireWall Switch Module)<br>
/^Flash(\s+\S+)+ \@ 0x\S+,\s+(\S+)/ &&<br>
ProcessHistory("COMMENTS","keysort","B2", "!Memory:
Flash $2\n") &&<br>
next;<br>
# CatOS 3500xl stuff<br>
/^system serial number\s*:\s+(.*)$/i &&<br>
ProcessHistory("COMMENTS","keysort","C1", "!Serial
Number: $1\n") &&<br>
next;<br>
/^Model / &&<br>
ProcessHistory("COMMENTS","keysort","C2", "!$_")
&& next;<br>
/^Motherboard / &&<br>
ProcessHistory("COMMENTS","keysort","C3", "!$_")
&& next;<br>
/^Power supply / &&<br>
ProcessHistory("COMMENTS","keysort","C4", "!$_")
&& next;<br>
<br>
/^Activation Key:\s+(.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","C2", "!$_")
&& next;<br>
/^ROM: \d+ Bootstrap .*(Version.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","G2",<br>
"!ROM Image: Bootstrap $1\n!\n") && next;<br>
/^ROM: .*(Version.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","G3","!ROM Image:
$1\n") && next;<br>
/^BOOTFLASH: .*(Version.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","G4","!BOOTFLASH:
$1\n") && next;<br>
/^BOOTLDR: .*(Version.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","G4","!BOOTLDR:
$1\n") && next;<br>
/^System image file is "([^\"]*)", booted via (\S*)/
&&<br>
# removed the booted source due to<br>
# CSCdk28131: cycling info in 'sh ver'<br>
# ProcessHistory("COMMENTS","keysort","F4","!Image: booted
via $2, $1\n") &&<br>
ProcessHistory("COMMENTS","keysort","F4","!Image: booted
$1\n") &&<br>
next;<br>
/^System image file is "([^\"]*)"$/ &&<br>
ProcessHistory("COMMENTS","keysort","F5","!Image: $1\n")
&& next;<br>
if
(/(\S+(?:\sseries)?)\s+(?:\((\S+)\)\s+processor|\(revision[^)]+\)).*\s+with
(\S+k) bytes/i) {<br>
$proc = $1;<br>
my($cpu) = $2;<br>
my($mem) = $3;<br>
my($device) = "router";<br>
<br>
# the next line ought to be the more specific cpu info,
grab it.<br>
# yet, some boards/IOS vers have a processor ID line
between these<br>
# two. grrr. make sure we dont grab the "software"
junk that<br>
# follows these lines by looking for "CPU at " or the
2600s<br>
# "processor: " unique string. there are undoubtedly
many other<br>
# incantations. for a slave, we dont get this info, its
just a<br>
# blank line.<br>
$_ = <INPUT>;<br>
if (/processor board id/i) {<br>
my($sn);<br>
<br>
if (/processor board id (\S+)/i) {<br>
$sn = $1;<br>
$sn =~ s/,$//;<br>
ProcessHistory("COMMENTS","keysort","D9",<br>
"!Processor ID: $sn\n");<br>
}<br>
$_ = <INPUT>;<br>
}<br>
$_ = "" if (! /(cpu at |processor: |$cpu processor,)/i);<br>
tr/\015//d;<br>
s/implementation/impl/i;<br>
if ($_ !~ /^\s*$/) {<br>
chomp;<br>
s/^/, /;<br>
}<br>
<br>
if ($proc eq "CSC") {<br>
$type = "AGS";<br>
} elsif ($proc eq "CSC4") {<br>
$type = "AGS+";<br>
} elsif ($proc =~ /1900/) {<br>
$type = "1900";<br>
$device = "switch";<br>
} elsif ($proc =~ /^(AS)?25[12][12]/) {<br>
$type = "2500";<br>
} elsif ($proc =~ /261[01]/ || $proc =~ /262[01]/ ) {<br>
$type = "2600";<br>
} elsif ($proc =~ /WS-C29/) {<br>
$type = "2900XL";<br>
$device = "switch";<br>
} elsif ($proc =~ /WS-C355/) {<br>
$type = "3550";<br>
$device = "switch";<br>
} elsif ($proc =~ /WS-C35/) {<br>
$type = "3500XL";<br>
$device = "switch";<br>
} elsif ($proc =~ /^36[0246][0-9]/) {<br>
$type = "3600";<br>
} elsif ($proc =~ /^37/) {<br>
$type = "3700";<br>
} elsif ($proc =~ /^38/) {<br>
$type = "3800";<br>
} elsif ($proc =~ /WS-C45/) {<br>
$type = "4500";<br>
$device = "switch";<br>
} elsif ( $proc =~ /^AS5300/) {<br>
$type = "AS5300";<br>
} elsif ( $proc =~ /^AS5350/) {<br>
$type = "AS5350";<br>
} elsif ( $proc =~ /^AS5400/) {<br>
$type = "AS5400";<br>
} elsif ($proc =~ /6000/) {<br>
$type = "6000";<br>
$device = "switch";<br>
} elsif ($proc eq "WK-C65") {<br>
$type = "6500";<br>
} elsif ($proc eq "RP") {<br>
$type = "7000";<br>
} elsif ($proc eq "RP1") {<br>
$type = "7000";<br>
} elsif ($proc =~ /720[246]/) {<br>
$type = "7200";<br>
} elsif ( $proc =~ /^73/) {<br>
$type = "7300";<br>
} elsif ($proc eq "RSP7000") {<br>
$type = "7500";<br>
} elsif ($proc =~ /RSP\d/) {<br>
$type = "7500";<br>
} elsif ($proc =~ /OSR-76/) {<br>
$type = "7600";<br>
} elsif ($proc =~ /CISCO76/) {<br>
$type = "7600";<br>
} elsif ($proc =~ /1200[48]\/(GRP|PRP)/ || $proc =~
/1201[26]\/(GRP|PRP)/) {<br>
$type = "12000";<br>
} elsif ($proc =~ /1201[26]-8R\/(GRP|PRP)/) {<br>
$type = "12000";<br>
} elsif ($proc =~ /1240[48]\/(GRP|PRP)/ || $proc =~
/1241[06]\/(GRP|PRP)/) {<br>
$type = "12400";<br>
} else {<br>
$type = $proc;<br>
}<br>
<br>
print STDERR "TYPE = $type\n" if ($debug);<br>
ProcessHistory("COMMENTS","keysort","A1",<br>
"!Chassis type:$slave $proc - a $type $device\n");<br>
ProcessHistory("COMMENTS","keysort","B1",<br>
"!Memory:$slave main $mem\n");<br>
if (defined($cpu)) {<br>
ProcessHistory("COMMENTS","keysort","A3",<br>
"!CPU:$slave $cpu$_$slaveslot\n");<br>
}<br>
next;<br>
}<br>
if (/(\S+) Silicon\s*Switch Processor/) {<br>
if (!defined($C0)) {<br>
$C0 = 1;
ProcessHistory("COMMENTS","keysort","C0","!\n");<br>
}<br>
ProcessHistory("COMMENTS","keysort","C2","!SSP: $1\n");<br>
$ssp = 1;<br>
$sspmem = $1;<br>
next;<br>
}<br>
/^(\d+[kK]) bytes of multibus/ &&<br>
ProcessHistory("COMMENTS","keysort","B2",<br>
"!Memory: multibus $1\n") && next;<br>
/^(\d+[kK]) bytes of (non-volatile|NVRAM)/ &&<br>
ProcessHistory("COMMENTS","keysort","B3",<br>
"!Memory: nvram $1\n") && next;<br>
/^(\d+[kK]) bytes of flash memory/ &&<br>
ProcessHistory("COMMENTS","keysort","B5","!Memory: flash
$1\n") &&<br>
next;<br>
/^(\d+[kK]) bytes of .*flash partition/ &&<br>
ProcessHistory("COMMENTS","keysort","B6",<br>
"!Memory: flash partition $1\n") && next;<br>
/^(\d+[kK]) bytes of Flash internal/ &&<br>
ProcessHistory("COMMENTS","keysort","B4",<br>
"!Memory: bootflash $1\n") && next;<br>
if (/^(\d+[kK]) bytes of (Flash|ATA)?.*PCMCIA .*(slot|disk)
?(\d)/i) {<br>
ProcessHistory("COMMENTS","keysort","B7",<br>
"!Memory: pcmcia $2 $3$4 $1\n");<br>
next;<br>
}<br>
if (/^(\d+[kK]) bytes of (slot|disk)(\d)/i) {<br>
ProcessHistory("COMMENTS","keysort","B7",<br>
"!Memory: pcmcia $2$3 $1\n");<br>
next;<br>
}<br>
if (/^WARNING/) {<br>
if (!defined($I0)) {<br>
$I0 = 1;<br>
ProcessHistory("COMMENTS","keysort","I0","!\n");<br>
}<br>
ProcessHistory("COMMENTS","keysort","I1","! $_");<br>
}<br>
if (/^Configuration register is (.*)$/) {<br>
$config_register = $1;<br>
next;<br>
}<br>
if (/^Configuration register on node \S+ is (.*)$/) {<br>
$config_register = $1 if (length($config_register) <
1);<br>
next;<br>
}<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show redundancy"<br>
sub ShowRedundancy {<br>
print STDERR " In ShowRedundancy: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^Version information for secondary in slot (\d+):/) {<br>
$slave = " Slave:";<br>
$slaveslot = ", slot $1";<br>
next;<br>
}<br>
<br>
/^IOS .* Software \(([A-Za-z0-9_-]*)\), .*Version\s+(.*)$/
&&<br>
ProcessHistory("COMMENTS","keysort","F1",<br>
"!Image:$slave Software: $1, $2\n") && next;<br>
/^Compiled (.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","F3",<br>
"!Image:$slave Compiled: $1\n") && next;<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show IDprom"<br>
sub ShowIDprom {<br>
my($tmp);<br>
<br>
print STDERR " In ShowIDprom: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
/FRU is .(.*)\'/ && ($tmp = $1);<br>
/Product Number = .(.*)\'/ &&<br>
ProcessHistory("COMMENTS","keysort","D0",<br>
"!Catalyst Chassis type: $1, $tmp\n");<br>
/Serial Number = .([0-9A-Za-z]+)/ &&<br>
ProcessHistory("COMMENTS","keysort","D1",<br>
"!Catalyst Chassis S/N: $1\n");<br>
/Manufacturing Assembly Number = .([-0-9]+)/ &&
($tmp = $1);<br>
/Manufacturing Assembly Revision = .(.*)\'/ && ($tmp
.= ", rev " . $1);<br>
/Hardware Revision = ([0-9.]+)/ &&<br>
ProcessHistory("COMMENTS","keysort","D2",<br>
"!Catalyst Chassis assembly: $tmp, ver $1\n");<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show install active"<br>
sub ShowInstallActive {<br>
print STDERR " In ShowInstallActive: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/^\s*\^\s*$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
ProcessHistory("COMMENTS","keysort","F5","!Image: $_")
&& next;<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show env all"<br>
sub ShowEnv {<br>
# Skip if this is not a 7500, 7200, or 7000.<br>
print STDERR " In ShowEnv: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
if (/^$prompt/) { $found_env = 1; last};<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
#return(1) if ($type !~ /^7/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(0) if ($found_env); # Only do this routine
once<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (!defined($E0)) {<br>
$E0 = 1;<br>
ProcessHistory("COMMENTS","keysort","E0","!\n");<br>
}<br>
if (/^Arbiter type (\d), backplane type (\S+)/) {<br>
if (!defined($C0)) {<br>
$C0 = 1;
ProcessHistory("COMMENTS","keysort","C0","!\n");<br>
}<br>
ProcessHistory("COMMENTS","keysort","C1",<br>
"!Enviromental Arbiter Type: $1\n");<br>
ProcessHistory("COMMENTS","keysort","A2",<br>
"!Chassis type: $2 backplane\n");<br>
next;<br>
}<br>
/^Power Supply Information$/ && next;<br>
/^\s*Power Module\s+Voltage\s+Current$/ && next;<br>
/^\s*(Power [^:\n]+)$/ &&<br>
ProcessHistory("COMMENTS","keysort","E1","!Power: $1\n")
&& next;<br>
/^\s*(Lower Power .*)/i &&<br>
ProcessHistory("COMMENTS","keysort","E2","!Power: $1\n")
&& next;<br>
/^\s*(redundant .*)/i &&<br>
ProcessHistory("COMMENTS","keysort","E2","!Power: $1\n")
&& next;<br>
/^\s*(RPS is .*)/i &&<br>
ProcessHistory("COMMENTS","keysort","E2","!Power: $1\n")
&& next;<br>
}<br>
ProcessHistory("COMMENTS","","","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show rsp chassis-info" for the rsp<br>
# This will create arrays for hw info.<br>
sub ShowRSP {<br>
print STDERR " In ShowRSP: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# return(1) if ($type !~ /^12[40]/);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
/^$/ && next;<br>
<br>
/^\s+Chassis model: (\S+)/ &&<br>
ProcessHistory("COMMENTS","keysort","D1",<br>
"!RSP Chassis model: $1\n") &&<br>
next;<br>
/^\s+Chassis S\/N: (.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","D2",<br>
"!RSP Chassis S/N: $1\n") &&<br>
next;<br>
}<br>
<br>
return(0);<br>
}<br>
<br>
# This routine parses "show gsr chassis-info" for the gsr<br>
# This will create arrays for hw info.<br>
sub ShowGSR {<br>
# Skip if this is not a 1200n.<br>
print STDERR " In ShowGSR: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# return(1) if ($type !~ /^12[40]/);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
/^$/ && next;<br>
<br>
/^\s+Chassis: type (\S+) Fab Ver: (\S+)/ &&<br>
ProcessHistory("COMMENTS","keysort","D1",<br>
"!GSR Chassis type: $1 Fab Ver: $2\n")
&&<br>
next;<br>
/^\s+Chassis S\/N: (.*)$/ &&<br>
ProcessHistory("COMMENTS","keysort","D2",<br>
"!GSR Chassis S/N: $1\n") &&<br>
next;<br>
/^\s+PCA: (\S+)\s*rev: (\S+)\s*dev: \S+\s*HW ver: (\S+)$/
&&<br>
ProcessHistory("COMMENTS","keysort","D3",<br>
"!GSR Backplane PCA: $1, rev $2, ver $3\n")
&&<br>
next;<br>
/^\s+Backplane S\/N: (\S+)$/ &&<br>
ProcessHistory("COMMENTS","keysort","D4",<br>
"!GSR Backplane S/N: $1\n") &&<br>
next;<br>
}<br>
ProcessHistory("COMMENTS","","","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show boot"<br>
sub ShowBoot {<br>
# Pick up boot variables if 7000/7200/7500/12000/2900/3500;<br>
# otherwise pick up bootflash.<br>
print STDERR " In ShowBoot: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/^\s*\^\s*$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(1) if (/Ambiguous command/i);<br>
return(1) if (/(Open device \S+ failed|Error opening
\S+:)/);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
next if /CONFGEN variable/;<br>
if (!defined($H0)) {<br>
$H0 = 1;
ProcessHistory("COMMENTS","keysort","H0","!\n");<br>
}<br>
if ($type !~ /^(12[04]|7)/) {<br>
if ($type !~ /^(29|35)00/) {<br>
ProcessHistory("COMMENTS","keysort","H2","!BootFlash:
$_");<br>
} else {<br>
ProcessHistory("COMMENTS","keysort","H1","!Variable:
$_");<br>
}<br>
} elsif (/(variable|register)/) {<br>
ProcessHistory("COMMENTS","keysort","H1","!Variable:
$_");<br>
}<br>
}<br>
ProcessHistory("COMMENTS","","","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show flash"<br>
sub ShowFlash {<br>
# skip if this is 7000, 7200, 7500, or 12000; else we end up
with<br>
# redundant data from dir /all slot0:<br>
print STDERR " In ShowFlash: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if ($type =~ /^(12[40]|7)/);<br>
return(1) if ($ios eq "XE");<br>
return(1) if (/^\s*\^\s*$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
# Filter dhcp database<br>
next if (/dhcp_[^. ]*\.txt/);<br>
<br>
/\s+(multiple-fs|nv_hdr|vlan\.dat)$/ && next;<br>
ProcessHistory("FLASH","","","!Flash: $_");<br>
}<br>
ProcessHistory("","","","!\n");<br>
return;<br>
}<br>
<br>
# This routine parses "dir /all ((disk|slot)N|bootflash|nvram):"<br>
sub DirSlotN {<br>
print STDERR " In DirSlotN: $_" if ($debug);<br>
<br>
my($dev) = (/\s([^\s]+):/);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if /^\s*\^\s*$/;<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(1) if (/(No such device|Error Sending Request)/i);<br>
return(1) if (/\%Error: No such file or directory/);<br>
return(1) if (/No space information available/);<br>
# Corrupt flash<br>
/\%Error calling getdents / &&<br>
ProcessHistory("FLASH","","","!Flash: $dev: $_")
&& next;<br>
return(-1) if (/\%Error calling/);<br>
return(-1) if (/(: device being squeezed|ATA_Status time
out)/i); # busy<br>
return(-1) if (/\%Error opening \S+:\S+ \(Device or resource
busy\)/i);<br>
return(-1) if (/command authorization failed/i);<br>
return(1) if (/(Open device \S+ failed|Error opening
\S+:)/);<br>
# filter frequently changing files from IOX bootflash<br>
if ($dev =~ /bootflash/) {<br>
next if (/temp_cont\s*$/);<br>
next if (/uptime_cont\s*$/);<br>
}<br>
# Filter dhcp database<br>
next if (/dhcp_[^. ]*\.txt/);<br>
<br>
if ($ios eq "XE" && /.*\((\d+) bytes free\)/) {<br>
my($tmp) = $1;<br>
if ($tmp >= (1024 * 1024 * 1024)) {<br>
$tmp = int($tmp / (1024 * 1024 * 1024));<br>
s/$1 bytes free/$tmp GB free/;<br>
} else { <br>
$tmp = int($tmp / (1024 * 1024));<br>
s/$1 bytes free/$tmp MB free/;<br>
}<br>
}<br>
if ($ios eq "XE" &&
/^((\s+)?\d+\s+\S+)\s+\d+.*(tracelogs$)/) {<br>
$_ = "$1" . sprintf("%43s", "") . "$3\n";<br>
}<br>
if ($ios eq "IOS" &&
/^((\s+)?\d+\s+\S+)\s+\d+.*(sflog$)/) {<br>
$_ = "$1" . sprintf("%43s", "") . "$3\n";<br>
}<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
ProcessHistory("FLASH","","","!Flash: $dev: $_");<br>
}<br>
ProcessHistory("","","","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show controllers"<br>
sub ShowContAll {<br>
# Skip if this is a 70[01]0, 7500, or 12000.<br>
print STDERR " In ShowContAll: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
# return(1) if ($type =~ /^(12[40]|7[05])/);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^Interface ([^ \n(]*)/) { $INT = "$1, "; next; }<br>
/^(BRI unit \d)/ &&<br>
ProcessHistory("INT","","","!Interface: $1\n")
&& next;<br>
/^LANCE unit \d, NIM/ &&<br>
ProcessHistory("INT","","","!Interface: $_") &&
next;<br>
/^(LANCE unit \d)/ &&<br>
ProcessHistory("INT","","","!Interface: $1\n")
&& next;<br>
/(Media Type is \S+),/ &&<br>
ProcessHistory("INT","","","!\t$1\n");<br>
if (/(M\dT[^ :]*:) show controller:$/) {<br>
my($ctlr) = $1;<br>
$_ = <INPUT>; tr/\015//d; s/ subunit \d,//;<br>
ProcessHistory("INT","","","!Interface: $ctlr $_");<br>
}<br>
if (/^(\S+) : show controller:$/) {<br>
my($ctlr) = $1;<br>
$_ = <INPUT>; tr/\015//d; s/ subunit \d,//;<br>
ProcessHistory("INT","","","!Interface: $ctlr: $_");<br>
}<br>
/^(HD unit \d), idb/ &&<br>
ProcessHistory("INT","","","!Interface: $1\n")
&& next;<br>
/^HD unit \d, NIM/ &&<br>
ProcessHistory("INT","","","!Interface: $_") &&
next;<br>
/^buffer size \d+ HD unit \d, (.*)/ &&<br>
ProcessHistory("INT","","","!\t$1\n") && next;<br>
/^AM79970 / &&
ProcessHistory("INT","","","!Interface: $_") && next;<br>
/^buffer size \d+ (Universal Serial: .*)/ &&<br>
ProcessHistory("INT","","","!\t$1\n") && next;<br>
/^Hardware is (.*)/ &&<br>
ProcessHistory("INT","","","!Interface: $INT$1\n")
&& next;<br>
/^(QUICC Serial unit \d),/ &&<br>
ProcessHistory("INT","","","!$1\n") && next;<br>
/^QUICC Ethernet .*/ &&<br>
ProcessHistory("INT","","","!$_") && next;<br>
/^DTE .*\.$/ &&<br>
ProcessHistory("INT","","","!\t$_") && next;<br>
/^(cable type :.*),/ &&<br>
ProcessHistory("INT","","","!\t$1\n") && next;<br>
/^(.* cable.*), received clockrate \d+$/ &&<br>
ProcessHistory("INT","","","!\t$1\n") && next;<br>
/^.* cable.*$/ &&<br>
ProcessHistory("INT","","","!\t$_") && next;<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show controllers cbus"<br>
# Some of this is printed out in ShowDiagbus.<br>
sub ShowContCbus {<br>
# Skip if this is not a 7000 or 7500.<br>
print STDERR " In ShowContCbus: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
#return(1) if ($type !~ /^7[05]0/);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^\s*slot(\d+): ([^,]+), hw (\S+), sw (\S+), ccb/) {<br>
$slot = $1;<br>
$board{$slot} = $2;<br>
$hwver{$slot} = $3;<br>
$hwucode{$slot} = $4;<br>
} elsif (/^\s*(\S+) (\d+), hardware version (\S+), microcode
version (\S+)/) {<br>
$slot = $2;<br>
$board{$slot} = $1;<br>
$hwver{$slot} = $3;<br>
$hwucode{$slot} = $4;<br>
} elsif (/(Microcode .*)/) {<br>
$ucode{$slot} = $1;<br>
} elsif (/(software loaded .*)/) {<br>
$ucode{$slot} = $1;<br>
} elsif (/(\d+) Kbytes of main memory, (\d+) Kbytes cache
memory/) {<br>
$hwmemd{$slot} = $1;<br>
$hwmemc{$slot} = $2;<br>
} elsif (/byte buffers/) {<br>
chop;<br>
s/^\s*//;<br>
$hwbuf{$slot} = $_;<br>
} elsif (/Interface (\d+) - (\S+ \S+),/) {<br>
$interface = $1;<br>
ProcessHistory("HW","","",<br>
"!\n!Int $interface: in slot $slot, named $2\n"); next;<br>
} elsif (/(\d+) buffer RX queue threshold, (\d+) buffer TX
queue limit, buffer size (\d+)/) {<br>
ProcessHistory("HW","","","!Int $interface: rxq $1, txq
$2, bufsize $3\n");<br>
next;<br>
}<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show debug"<br>
sub ShowDebug {<br>
print STDERR " In ShowDebug: $_" if ($debug);<br>
my($lines) = 0;<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
/^No matching debug flags set$/ && next;<br>
/^No debug flags set$/ && next;<br>
ProcessHistory("COMMENTS","keysort","J1","!DEBUG: $_");<br>
$lines++;<br>
}<br>
if ($lines) {<br>
ProcessHistory("COMMENTS","keysort","J0","!\n");<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show diagbus"<br>
# This will create arrays for hw info.<br>
sub ShowDiagbus {<br>
# Skip if this is not a 7000, 70[01]0, or 7500.<br>
print STDERR " In ShowDiagbus: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
#return(1) if ($type !~ /^7[05]/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^\s*Slot (\d+):/i) {<br>
$slot = $1;<br>
next;<br>
} elsif (/^\s*Slot (\d+) \(virtual\):/i) {<br>
$slot = $1;<br>
next;<br>
} elsif
(/^\s*(.*Processor.*|.*controller|.*controler|.*Chassis
Interface)(, FRU\s?:.*)?, HW rev (\S+), board revision (\S+)/i)
{<br>
$board = $1;<br>
$hwver = $3;<br>
$boardrev = $4;<br>
if ($board =~ /Processor/) {<br>
if ($board =~ /7000 Route\/Switch/) {<br>
$board = "RSP7000";<br>
} elsif ($board =~ /Route\/Switch Processor (\d)/) {<br>
$board = "RSP$1";<br>
} elsif ($board =~ /Route/) {<br>
$board = "RP";<br>
} elsif ($board =~ /Silicon Switch/) {<br>
$board = "SSP";<br>
} elsif ($board =~ /Switch/) {<br>
$board = "SP";<br>
$board = "SSP $sspmem" if $ssp;<br>
} elsif ($board =~ /ATM/) {<br>
$board = "AIP";<br>
}<br>
} elsif ($board =~ /(.*) controller/i) {<br>
$board = $1;<br>
}<br>
# hwucode{$slot} defined in ShowContCbus<br>
if (defined $hwucode{$slot}) {<br>
ProcessHistory("SLOT","","","!\n!Slot $slot/$board:
hvers $hwver rev $boardrev ucode $hwucode{$slot}\n");<br>
} else {<br>
ProcessHistory("SLOT","","","!\n!Slot $slot/$board:
hvers $hwver rev $boardrev\n");<br>
}<br>
# These are also from the ShowContCbus<br>
ProcessHistory("SLOT","","","!Slot $slot/$board:
$ucode{$slot}\n") if (defined $ucode{$slot});<br>
ProcessHistory("SLOT","","","!Slot $slot/$board: memd
$hwmemd{$slot}, cache $hwmemc{$slot}\n")<br>
if ((defined $hwmemd{$slot}) && (defined
$hwmemc{$slot}));<br>
ProcessHistory("SLOT","","","!Slot $slot/$board:
$hwbuf{$slot}\n") if (defined $hwbuf{$slot});<br>
next;<br>
}<br>
/Serial number: (\S+)\s*Part number: (\S+)/ &&<br>
ProcessHistory("SLOT","","",<br>
"!Slot $slot/$board: part $2, serial $1\n")
&&<br>
next;<br>
/^\s*Controller Memory Size: (.*)$/ &&<br>
ProcessHistory("SLOT","","","!Slot $slot/$board: $1\n")
&&<br>
next;<br>
if (/PA Bay (\d) Information/) {<br>
$pano = $1;<br>
if ("PA" =~ /$board/) {<br>
($s,$c) = split(/\//,$board);<br>
$board = "$s/$c/PA $pano";<br>
} else {<br>
$board =~ s/\/PA \d//;<br>
$board = "$board/PA $pano";<br>
}<br>
next;<br>
}<br>
/\s+(.*) (IP|PA), (\d) ports?,( \S+,)? (FRU\s?: )?(\S+)/
&&<br>
ProcessHistory("SLOT","","","!Slot $slot/$board: type
$6, $3 ports\n") &&<br>
next;<br>
/\s+(.*) (IP|PA)( \(\S+\))?, (\d) ports?/ &&<br>
ProcessHistory("SLOT","","","!Slot $slot/$board: type
$1$3, $4 ports\n") &&<br>
next;<br>
/^\s*HW rev (\S+), Board revision (\S+)/ &&<br>
ProcessHistory("SLOT","","","!Slot $slot/$board: hvers
$1 rev $2\n") &&<br>
next;<br>
/Serial number: (\S+)\s*Part number: (\S+)/ &&<br>
ProcessHistory("SLOT","","","!Slot $slot/$board: part
$2, serial $1\n") && next;<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show diag" for the gsr, 7200, 3700, 3600,
2600.<br>
# This will create arrays for hw info.<br>
sub ShowDiag {<br>
print STDERR " In ShowDiag: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
REDUX: tr/\015//d;<br>
if (/^$prompt/) { $found_diag = 1; last};<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(0) if ($found_diag); # Only do this routine
once<br>
return(-1) if (/command authorization failed/i);<br>
/^$/ && next;<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
s/Port Packet Over SONET/POS/;<br>
if (/^\s*SLOT\s+(\d+)\s+\((.*)\): (.*)/) {<br>
$slot = $1;<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","A","!Slot $slot:
$3\n");<br>
next;<br>
}<br>
if (/^\s*NODE\s+(\S+) : (.*)/) {<br>
$slot = $1;<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","A","!Slot $slot:
$2\n");<br>
next;<br>
}<br>
if (/^\s*PLIM\s+(\S+) : (.*)/) {<br>
$slot = $1 . " PLIM";<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","A","!Slot $slot:
$2\n");<br>
next;<br>
}<br>
if (/^\s*RACK\s+(\S+) : (.*)/) {<br>
$slot = "Rack/" . $1;<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","A","!Slot $slot:
$2\n");<br>
next;<br>
}<br>
if (/^\s+MAIN:\s* type \S+,\s+(.*)/) {<br>
local($part) = $1;<br>
$_ = <INPUT>;<br>
if (/^\s+(HW version|Design Release) (\S+)\s+S\/N
(\S+)/i) {<br>
ProcessHistory("SLOT","keysort","AM","!Slot $slot/MAIN:
part $part, serial $3\n");<br>
ProcessHistory("SLOT","keysort","AM","!Slot $slot/MAIN:
hvers $2\n");<br>
} else {<br>
ProcessHistory("SLOT","keysort","AM","!Slot $slot/MAIN:
part $part\n");<br>
goto REDUX;<br>
}<br>
next;<br>
}<br>
if (/^\s+MAIN:\s* board type \S+$/) {<br>
$_ = <INPUT>;<br>
tr/\015//d;<br>
if (/^\s+(.+)$/) {<br>
local($part) = $1;<br>
$_ = <INPUT>;<br>
tr/\015//d;<br>
if (/^\s+dev (.*)$/) {<br>
local($dev) = $1;<br>
$_ = <INPUT>;<br>
if (/^\s+S\/N (\S+)/) {<br>
ProcessHistory("SLOT","keysort","AM","!Slot
$slot/MAIN: part $part, dev $dev, serial $1\n");<br>
} else {<br>
ProcessHistory("SLOT","keysort","AM","!Slot
$slot/MAIN: part $part, dev $dev\n");<br>
goto REDUX;<br>
}<br>
} else {<br>
ProcessHistory("SLOT","keysort","AM","!Slot
$slot/MAIN: part $part\n");<br>
goto REDUX;<br>
}<br>
} else {<br>
goto REDUX;<br>
}<br>
next;<br>
}<br>
if (/^c3700\s+(io-board|mid-plane)/i) {<br>
$slot = $1;<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","A","!Slot $slot: part
$1\n");<br>
next;<br>
}<br>
if (/ Engine:\s+(.*)/) {<br>
ProcessHistory("SLOT","keysort","AE","!Slot
$slot/Engine: $1\n");<br>
}<br>
if (/FRU:\s+Linecard\/Module:\s+(\S+)/) {<br>
ProcessHistory("SLOT","keysort","AF","!Slot $slot/FRU:
Linecard/Module: $1\n");<br>
next;<br>
}<br>
if (/\s+Processor Memory:\s+(\S+)/) {<br>
ProcessHistory("SLOT","keysort","AF","!Slot $slot/FRU:
Processor Memory: $1\n");<br>
next;<br>
}<br>
if (/\s+Packet Memory:\s+(\S+)/) {<br>
ProcessHistory("SLOT","keysort","AF","!Slot $slot/FRU:
Packet Memory: $1\n");<br>
next;<br>
}<br>
if (/\s+Route Memory:\s+(\S+)/) {<br>
ProcessHistory("SLOT","keysort","AF","!Slot $slot/FRU:
Route Memory: $1\n");<br>
next;<br>
}<br>
if (/^\s+PCA:\s+(.*)/) {<br>
local($part) = $1;<br>
$_ = <INPUT>;<br>
if (/^\s+(HW version|design release) (\S+)\s+S\/N
(\S+)/i) {<br>
ProcessHistory("SLOT","keysort","C1","!Slot $slot/PCA:
part $part, serial $3\n");<br>
ProcessHistory("SLOT","keysort","C2","!Slot $slot/PCA:
hvers $2\n");<br>
} else {<br>
ProcessHistory("SLOT","keysort","C1","!Slot $slot/PCA:
part $part\n");<br>
goto REDUX;<br>
}<br>
next;<br>
}<br>
if (/^\s+MBUS: .*\)\s+(.*)/) {<br>
local($tmp) = "!Slot $slot/MBUS: part $1";<br>
$_ = <INPUT>;<br>
/^\s+HW version (\S+)\s+S\/N (\S+)/ &&<br>
ProcessHistory("SLOT","keysort","MB1","$tmp, serial
$2\n") &&<br>
ProcessHistory("SLOT","keysort","MB2","!Slot $slot/MBUS:
hvers $1\n");<br>
next;<br>
}<br>
if (/^\s+MBUS Agent Software version (.*)/) {<br>
ProcessHistory("SLOT","keysort","MB3","!Slot $slot/MBUS:
software $1\n");<br>
next;<br>
}<br>
if (/^\s+PLD: (.*)/) {<br>
ProcessHistory("SLOT","keysort","P","!Slot $slot/PLD:
$1\n");<br>
next;<br>
}<br>
if (/^\s+MONLIB: (.*)/) {<br>
ProcessHistory("SLOT","keysort","Q","!Slot $slot/MONLIB:
$1\n");<br>
next;<br>
}<br>
if (/^\s+ROM Monitor version (.*)/) {<br>
ProcessHistory("SLOT","keysort","R","!Slot $slot/ROM
Monitor: version $1\n");<br>
next;<br>
}<br>
if (/^\s+ROMMON: Version (.*)/) {<br>
ProcessHistory("SLOT","keysort","R","!Slot $slot/ROMMON:
version $1\n");<br>
next;<br>
}<br>
if (/^\s+Fabric Downloader version used (.*)/) {<br>
ProcessHistory("SLOT","keysort","Z","!Slot $slot/Fabric
Downloader: version $1\n");<br>
next;<br>
}<br>
if (/^\s+DRAM size: (\d+)/) {<br>
local($dram) = $1 / 1048576;<br>
$_ = <INPUT>;<br>
if (/^\s+FrFab SDRAM size: (\d+)/) {<br>
ProcessHistory("SLOT","keysort","MB4","!Slot $slot/MBUS:
$dram Mbytes DRAM, "<br>
. $1 / 1024 . " Kbytes SDRAM\n");<br>
} else {<br>
ProcessHistory("SLOT","keysort","MB4","!Slot $slot/MBUS:
$dram Mbytes DRAM\n");<br>
goto REDUX;<br>
}<br>
next;<br>
}<br>
# 7200, 3600, 2600, and 1700 stuff<br>
if (/^(Slot)\s+(\d+(\/\d+)?):/<br>
|| /^\s+(WIC|VIC|WIC\/VIC) Slot (\d):/<br>
|| /^(Encryption AIM) (\d):/) {<br>
if ($1 eq "WIC") {<br>
$WIC = "/$2";<br>
} elsif ($1 eq "VIC") {<br>
$WIC = "/$2";<br>
} elsif ($1 eq "WIC/VIC") {<br>
$WIC = "/$2";<br>
} elsif ($1 eq "DSP") {<br>
$WIC = "/$2";<br>
} elsif ($1 eq "Encryption AIM") {<br>
$slot = "$2";<br>
undef($WIC);<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","B","!Slot $slot: type
$1\n");<br>
next;<br>
} else {<br>
$slot = $2;<br>
undef($WIC);<br>
}<br>
$_ = <INPUT>; tr/\015//d;<br>
<br>
# clean up hideous 7200/etc formats to look more like
7500 output<br>
s/Fast-ethernet on C7200 I\/O card/FE-IO/;<br>
s/ with MII or RJ45/-TX/;<br>
s/Fast-ethernet /100Base/; s/[)(]//g;<br>
s/intermediate reach/IR/i;<br>
<br>
ProcessHistory("SLOT","","","!\n");<br>
/\s+(.*) port adapter,?\s+(\d+)\s+/i &&<br>
ProcessHistory("SLOT","keysort","B",<br>
"!Slot $slot: type $1, $2 ports\n")
&& next;<br>
# I/O controller with no interfaces<br>
/\s+(.*)\s+port adapter\s*$/i &&<br>
ProcessHistory("SLOT","keysort","B",<br>
"!Slot $slot: type $1, 0 ports\n") &&
next;<br>
/\s+(.*)\s+daughter card(.*)$/ &&<br>
ProcessHistory("SLOT","keysort","B",<br>
"!Slot $slot$WIC: type $1$2\n") &&
next;<br>
/\s+(FT1)$/ &&<br>
ProcessHistory("SLOT","keysort","B",<br>
"!Slot $slot$WIC: type $1\n") &&
next;<br>
# AS5300/5400 handling<br>
/^Hardware is\s+(.*)$/i &&<br>
ProcessHistory("SLOT","keysort","B","!Slot $slot: type
$1\n")<br>
&& next;<br>
/^DFC type is\s+(.*)$/i &&<br>
ProcessHistory("SLOT","keysort","B","!Slot $slot: type
$1\n")<br>
&& next;<br>
#<br>
# handle WICs lacking "daughter card" in the 2nd line of
their<br>
# show diag o/p<br>
if (defined($WIC)) {<br>
s/^\s+//;<br>
ProcessHistory("SLOT","keysort","B","!Slot $slot$WIC:
type $_");<br>
}<br>
next;<br>
} elsif (/^\s+(.* (DSP) Module) Slot (\d):/) {<br>
# The 1760 (at least) has yet another format...where it
has two<br>
# dedicated DSP slots, and thus two slot 0s.<br>
my($TYPE) = $1;<br>
$WIC = "/$3";<br>
ProcessHistory("SLOT","","","!\n");<br>
ProcessHistory("SLOT","keysort","B",<br>
"!Slot $slot$WIC: type $TYPE\n");<br>
next;<br>
}<br>
# yet another format. seen on 2600s w/ 12.1, but appears to
be all<br>
# 12.1, including 7200s & 3700s. Sometimes the PCB
serial appears<br>
# before the hardware revision.<br>
if (/(pcb serial number|hardware revision)\s+:\s+(\S+)$/i) {<br>
my($hw, $pn, $rev, $sn);<br>
if ($1 =~ /^pcb/i) {<br>
$sn = $2;<br>
} else {<br>
$hw = $2;<br>
}<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
<br>
# Sometimes "show diag" just ends while we are<br>
# trying to process this pcb stuff. Check for a<br>
# prompt so we can get out.<br>
if (/^$prompt/) {<br>
$found_diag=1;<br>
goto PerlSucks;<br>
}<br>
<br>
if (/0x..: / || /^$/) {<br>
# no effing idea why break does not work there<br>
goto PerlSucks;<br>
}<br>
if (/hardware revision\s+:\s+(\S+)/i) { $hw = $1; }<br>
if (/part number\s+:\s+(\S+)/i) { $pn = $1; }<br>
if (/board revision\s+:\s+(\S+)/i) { $rev = $1; }<br>
if (/pcb serial number\s+:\s+(\S+)/i) { $sn = $1; }<br>
# fru/pid bits, true Cisco evolving "standard",
hopefully<br>
# "show inventory" will be "the way" soon.<br>
#<br>
if (/product \(fru\) number\s+:\s+(\S+)/i) { $fn = $1; }<br>
if (/product number\s+:\s+(\S+)/i) { $fn = $1; }<br>
if (/product\s+identifier\s+\(PID\)\s+:\s+(\S+)/i) { $fn
= $1; }<br>
if (/fru\s+part\s+number\s+(\S+)/i) { $fn = $1; }<br>
}<br>
PerlSucks:<br>
# fru/pid bits<br>
ProcessHistory("SLOT","keysort","AG","!Slot $slot$WIC:
fru $fn\n");<br>
#<br>
ProcessHistory("SLOT","keysort","B","!Slot $slot$WIC:
hvers $hw rev $rev\n");<br>
ProcessHistory("SLOT","keysort","C","!Slot $slot$WIC:
part $pn, serial $sn\n");<br>
# If we saw the prompt, then we are done.<br>
last if $found_diag;<br>
}<br>
/revision\s+(\S+).*revision\s+(\S+)/ &&<br>
ProcessHistory("SLOT","keysort","C","!Slot $slot$WIC:
hvers $1 rev $2\n") &&<br>
next;<br>
/number\s+(\S+)\s+Part number\s+(\S+)/ &&<br>
ProcessHistory("SLOT","keysort","D","!Slot $slot$WIC:
part $2, serial $1\n") &&<br>
next;<br>
# AS5x00 bits<br>
/^\ Board Revision\s+(\S+),\s+Serial Number\s+(\S+),/
&&<br>
ProcessHistory("SLOT","keysort","D",<br>
"!Slot $slot$WIC: rev $1, serial $2\n")
&& next;<br>
/^\ Board Hardware Version\s+(\S+),\s+Item Number\s+(\S+),/
&&<br>
ProcessHistory("SLOT","keysort","D",<br>
"!Slot $slot$WIC: hvers $1, part $2\n")
&& next;<br>
/^Motherboard Info:/ &&<br>
ProcessHistory("SLOT","keysort","D",<br>
"!Slot $slot$WIC: Motherboard\n") &&
next;<br>
#<br>
}<br>
ProcessHistory("SLOT","","","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show inventory".<br>
sub ShowInventory {<br>
print STDERR " In ShowInventory: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
return if (/^\s*\^$/);<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^(NAME: "[^"]*",) (DESCR: "[^"]+")/) {<br>
ProcessHistory("INVENTORY","","", sprintf("!%-30s %s\n",
$1, $2));<br>
next;<br>
}<br>
# split PID/VID/SN line<br>
if (/^PID: (\S*)\s*,\s*VID: (\S*)\s*,\s*SN: (\S*)\s*$/) {<br>
my($entries) = "";<br>
$entries .= "!PID: $1\n" if ($1);<br>
$entries .= "!VID: $2\n" if ($2);<br>
$entries .= "!SN: $3\n" if ($3);<br>
ProcessHistory("INVENTORY","","", "$entries");<br>
next;<br>
}<br>
ProcessHistory("INVENTORY","","","!$_");<br>
}<br>
ProcessHistory("INVENTORY","","","!\n");<br>
<br>
return(0);<br>
}<br>
<br>
# This routine parses "show module".<br>
sub ShowModule {<br>
print STDERR " In ShowModule: $_" if ($debug);<br>
<br>
my(@lines);<br>
my($slot, $pa);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
return if (/^\s*\^$/);<br>
last if (/online diag status/i);<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
# match slot/card info line<br>
if (/^ *(\d+)\s+(\d+)\s+(.*)\s+(\S+)\s+(\S+)\s*$/) {<br>
$lines[$1 * 1000] .= "!Slot $1: type $3, $2 ports\n!Slot
$1: part $4, serial $5\n";<br>
$lines[$1 * 1000] =~ s/\s+,/,/g;<br>
next;<br>
}<br>
# now match the Revs in the second paragraph of o/p and
stick it in<br>
# the array with the previous bits...grumble.<br>
if (/^
*(\d+)\s+\S+\s+to\s+\S+\s+(\S+)\s+(\S*)\s+(\S+)(\s+\S+)?\s*$/) {<br>
$lines[$1 * 1000] .= "!Slot $1: hvers $2, firmware $3,
sw $4\n";<br>
$lines[$1 * 1000] =~ s/\s+,/,/g;<br>
next;<br>
}<br>
# grab the sub-modules, if any<br>
if (/^\s+(\d+)\s(.*)\s+(\S+)\s+(\S+)\s+(\S+)\s+\S+\s*$/) {<br>
my($idx);<br>
$pa = 0 if ($1 != $slot);<br>
$slot = $1;<br>
$idx = $1 * 1000 + $1 * 10 + $pa;<br>
$lines[$idx] .= "!Slot $1/$pa: type $2\n";<br>
$lines[$idx] .= "!Slot $slot/$pa: part $3, serial $4\n";<br>
$lines[$idx] .= "!Slot $slot/$pa: hvers $5\n";<br>
$pa++;<br>
}<br>
}<br>
foreach $slot (@lines) {<br>
next if ($slot =~ /^\s*$/);<br>
ProcessHistory("Module","","","$slot!\n");<br>
}<br>
<br>
return(0);<br>
}<br>
<br>
# This routine parses "show spe version".<br>
sub ShowSpeVersion {<br>
print STDERR " In ShowSpeVersion: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if /^\s*\^\s*$/;<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(-1) if (/command authorization failed/i);<br>
<br>
ProcessHistory("MODEM","","","!Modem: $_") && next;<br>
}<br>
ProcessHistory("MODEM","","","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show c7200" for the 7200<br>
# This will create arrays for hw info.<br>
sub ShowC7200 {<br>
# Skip if this is not a 7200.<br>
print STDERR " In ShowC7200: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
#return(1) if ($type !~ /^72/);<br>
return(-1) if (/command authorization failed/i);<br>
/^$/ && next;<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^(C7200 )?Midplane EEPROM:/) {<br>
$_ = <INPUT>;<br>
/revision\s+(\S+).*revision\s+(\S+)/;<br>
ProcessHistory("SLOT","","","!Slot Midplane: hvers $1
rev $2\n");<br>
$_ = <INPUT>;<br>
/number\s+(\S+)\s+Part number\s+(\S+)/;<br>
ProcessHistory("SLOT","","","!Slot Midplane: part $2,
serial $1\n!\n");<br>
next;<br>
}<br>
if (/C720\d(VXR)? CPU EEPROM:/) {<br>
my ($hvers,$rev,$part,$serial);<br>
# npe400s report their cpu eeprom info differently w/
12.0.21S<br>
while (<INPUT>) {<br>
/Hardware Revision\s+: (\S+)/ && ($hvers = $1)
&& next;<br>
/Board Revision\s+: (\S+)/ && ($rev = $1)
&& next;<br>
/Part Number\s+: (\S+)/ && ($part = $1)
&& next;<br>
/Serial Number\s+: (\S+)/ && ($serial = $1)
&& next;<br>
/revision\s+(\S+).*revision\s+(\S+)/ &&<br>
($hvers = $1, $rev = $2) && next;<br>
/number\s+(\S+)\s+Part number\s+(\S+)/ &&<br>
($serial = $1, $part = $2) && next;<br>
/^\s*$/ && last;<br>
}<br>
ProcessHistory("SLOT","","","!Slot CPU: hvers $hvers rev
$rev\n");<br>
ProcessHistory("SLOT","","","!Slot CPU: part $part,
serial $serial\n!\n");<br>
next;<br>
}<br>
}<br>
return(0);<br>
}<br>
<br>
# This routine parses "show vtp status"<br>
sub ShowVTP {<br>
print STDERR " In ShowVTP: $_" if ($debug);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if /^\s*\^\s*$/;<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);<br>
return(-1) if (/command authorization failed/i);<br>
next if (/^Configuration last modified by/);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
if (/^VTP Operating Mode\s+:\s+(Transparent|Server)/) {<br>
$DO_SHOW_VLAN = 1;<br>
}<br>
ProcessHistory("COMMENTS","keysort","I0","!VTP: $_");<br>
}<br>
ProcessHistory("COMMENTS","keysort","I0","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine parses "show vlan"<br>
sub ShowVLAN {<br>
print STDERR " In ShowVLAN: $_" if ($debug);<br>
<br>
($_ = <INPUT>, return(1)) if (!$DO_SHOW_VLAN);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
next if (/^(\s*|\s*$cmd\s*)$/);<br>
return(1) if /^\s*\^\s*$/;<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(1) if (/Ambiguous command/i);<br>
return(-1) if (/command authorization failed/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
<br>
ProcessHistory("COMMENTS","keysort","IO","!VLAN: $_");<br>
}<br>
ProcessHistory("COMMENTS","keysort","IO","!\n");<br>
return(0);<br>
}<br>
<br>
# This routine processes a "write term"<br>
sub WriteTerm {<br>
print STDERR " In WriteTerm: $_" if ($debug);<br>
my($lineauto,$comment,$linecnt) = (0,0,0);<br>
<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
return(1) if (!$linecnt && /^\s+\^\s*$/);<br>
next if (/^\s*$cmd\s*$/);<br>
return(1) if (/Line has invalid autocommand /);<br>
return(1) if (/(Invalid (input|command) detected|Type help
or )/i);<br>
return(1) if (/\%Error: No such file or directory/);<br>
return(1) if (/(Open device \S+ failed|Error opening
\S+:)/);<br>
return(0) if ($found_end); # Only do this routine
once<br>
return(-1) if (/command authorization failed/i);<br>
return(-1) if (/% ?configuration buffer full/i);<br>
# the pager can not be disabled per-session on the PIX<br>
if (/^(<-+ More -+>)/) {<br>
my($len) = length($1);<br>
s/^$1\s{$len}//;<br>
}<br>
/^! no configuration change since last restart/i &&
next;<br>
# skip emtpy lines at the beginning<br>
if (!$linecnt && /^\s*$/) {<br>
next;<br>
}<br>
if (!$linecnt && defined($config_register)) {<br>
ProcessHistory("","","", "!\nconfig-register
$config_register\n");<br>
}<br>
<br>
/Non-Volatile memory is in use/ && return(-1); #
NvRAM is locked<br>
/% Configuration buffer full, / && return(-1); #
buffer is in use<br>
$linecnt++;<br>
$lineauto = 0 if (/^[^ ]/);<br>
# skip the crap<br>
if (/^(##+|(building|current) configuration)/i) {<br>
while (<INPUT>) {<br>
next if (/^Current configuration\s*:/i);<br>
next if (/^:/);<br>
next if (/^([%!].*|\s*)$/);<br>
next if (/^ip add.*ipv4:/); # band-aid for 3620 12.0S<br>
last;<br>
}<br>
tr/\015//d;<br>
}<br>
# skip ASA 5520 configuration author line<br>
/^: written by /i && next;<br>
# some versions have other crap mixed in with the bits in
the<br>
# block above<br>
/^! (Last configuration|NVRAM config last)/ && next;<br>
# and for the ASA<br>
/^: (Written by \S+ at|Saved)/ && next;<br>
<br>
# skip consecutive comment lines to avoid oscillating extra
comment<br>
# line on some access servers. grrr.<br>
if (/^!\s*$/) {<br>
next if ($comment);<br>
ProcessHistory("","","",$_);<br>
$comment++;<br>
next;<br>
}<br>
$comment = 0;<br>
<br>
# Dog gone Cool matches to process the rest of the config<br>
/^tftp-server flash / && next; # kill any tftp
remains<br>
/^ntp clock-period / && next; # kill ntp
clock-period<br>
/^ length / && next; # kill length on serial
lines<br>
/^ width / && next; # kill width on serial
lines<br>
$lineauto = 1 if /^ modem auto/;<br>
/^ speed / && $lineauto && next; # kill
speed on serial lines<br>
/^ clockrate / && next; # kill clockrate on
serial interfaces<br>
if (/^(enable )?(password|passwd)( level \d+)? / &&
$filter_pwds >= 1) {<br>
ProcessHistory("ENABLE","","","!$1$2$3
<removed>\n");<br>
next;<br>
}<br>
if (/^(enable secret) / && $filter_pwds >= 2) {<br>
ProcessHistory("ENABLE","","","!$1 <removed>\n");<br>
next;<br>
}<br>
if (/^username (\S+)(\s.*)? secret /) {<br>
if ($filter_pwds >= 2) {<br>
ProcessHistory("USER","keysort","$1",<br>
"!username $1$2 secret <removed>\n");<br>
} else {<br>
ProcessHistory("USER","keysort","$1","$_");<br>
}<br>
next;<br>
}<br>
if (/^username (\S+)(\s.*)? password ((\d) \S+|\S+)/) {<br>
if ($filter_pwds >= 2) {<br>
ProcessHistory("USER","keysort","$1",<br>
"!username $1$2 password <removed>\n");<br>
} elsif ($filter_pwds >= 1 && $4 ne "5"){<br>
ProcessHistory("USER","keysort","$1",<br>
"!username $1$2 password <removed>\n");<br>
} else {<br>
ProcessHistory("USER","keysort","$1","$_");<br>
}<br>
next;<br>
}<br>
# cisco AP w/ IOS<br>
if (/^(wlccp \S+ username (\S+)(\s.*)? password) (\d
\S+|\S+)/) {<br>
if ($filter_pwds >= 1) {<br>
ProcessHistory("USER","keysort","$2","!$1
<removed>\n");<br>
} else {<br>
ProcessHistory("USER","keysort","$2","$_");<br>
}<br>
next;<br>
}<br>
# filter auto "rogue ap" configuration lines<br>
/^rogue ap classify / && next;<br>
if (/^( set session-key (in|out)bound ah \d+ )/ &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1<removed>\n");<br>
next;<br>
}<br>
if (/^( set session-key (in|out)bound esp \d+
(authenticator|cypher) )/<br>
&& $filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1<removed>\n");<br>
next;<br>
}<br>
if (/^(\s*)password / && $filter_pwds >= 1) {<br>
ProcessHistory("LINE-PASS","","","!$1password
<removed>\n");<br>
next;<br>
}<br>
if (/^(\s*)secret / && $filter_pwds >= 2) {<br>
ProcessHistory("LINE-PASS","","","!$1secret
<removed>\n");<br>
next;<br>
}<br>
if (/^\s*neighbor (\S*) password / && $filter_pwds
>= 1) {<br>
ProcessHistory("","","","! neighbor $1 password
<removed>\n");<br>
next;<br>
}<br>
if (/^(ppp .* password) 7 .*/ && $filter_pwds >=
1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
if (/^(ip ftp password) / && $filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
if (/^( ip ospf authentication-key) / &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
# isis passwords appear to be completely plain-text<br>
if (/^\s+isis password (\S+)( .*)?/ && $filter_pwds
>= 1) {<br>
ProcessHistory("","","","!isis password
<removed>$2\n"); next;<br>
}<br>
if (/^\s+(domain-password|area-password) (\S+)( .*)?/<br>
&& $filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>$3\n");
next;<br>
}<br>
# this is reversable, despite 'md5' in the cmd<br>
if (/^( ip ospf message-digest-key \d+ md5) / &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
# this is also reversable, despite 'md5 encrypted' in the
cmd<br>
if (/^( message-digest-key \d+ md5 (7|encrypted)) /<br>
&& $filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
if (/^((crypto )?isakmp key) \S+ / && $filter_pwds
>= 1) {<br>
ProcessHistory("","","","!$1 <removed> $'"); next;<br>
}<br>
# filter HSRP passwords<br>
if (/^(\s+standby \d+ authentication) / &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
# this appears in "measurement/sla" images<br>
if (/^(\s+key-string \d?)/ && $filter_pwds >= 1)
{<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
if (/^( l2tp tunnel \S+ password)/ && $filter_pwds
>= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
# i am told these are plain-text on the PIX<br>
if (/^(vpdn username (\S+) password)/) {<br>
if ($filter_pwds >= 1) {<br>
ProcessHistory("USER","keysort","$2","!$1
<removed>\n");<br>
} else {<br>
ProcessHistory("USER","keysort","$2","$_");<br>
}<br>
next;<br>
}<br>
# ASA/PIX keys in more system:running-config<br>
if (/^( pre-shared-key | key |failover key ).*/ &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed> $'"); next;<br>
}<br>
if (/(\s+ldap-login-password )\S+(.*)/ &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed> $'"); next;<br>
}<br>
#<br>
if (/^( cable shared-secret )/ && $filter_pwds >=
1) {<br>
ProcessHistory("","","","!$1 <removed>\n");<br>
next;<br>
}<br>
/fair-queue individual-limit/ && next;<br>
# sort ip explicit-paths.<br>
if (/^ip explicit-path name (\S+)/) {<br>
my($key) = $1;<br>
my($expath) = $_;<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/);<br>
last if (/^$prompt/ || ! /^(ip explicit-path name |[
!])/);<br>
if (/^ip explicit-path name (\S+)/) {<br>
ProcessHistory("EXPATH","keysort","$key","$expath");<br>
$key = $1;<br>
$expath = $_;<br>
} else {<br>
$expath .= $_;<br>
}<br>
}<br>
ProcessHistory("EXPATH","keysort","$key","$expath");<br>
}<br>
# sort route-maps<br>
if (/^route-map (\S+)/) {<br>
my($key) = $1;<br>
my($routemap) = $_;<br>
while (<INPUT>) {<br>
tr/\015//d;<br>
last if (/^$prompt/ || ! /^(route-map |[ !])/);<br>
if (/^route-map (\S+)/) {<br>
ProcessHistory("ROUTEMAP","keysort","$key","$routemap");<br>
$key = $1;<br>
$routemap = $_;<br>
} else {<br>
$routemap .= $_;<br>
}<br>
}<br>
ProcessHistory("ROUTEMAP","keysort","$key","$routemap");<br>
}<br>
# filter out any RCS/CVS tags to avoid confusing local CVS
storage<br>
s/\$(Revision|Id):/ $1:/;<br>
# order access-lists<br>
/^access-list\s+(\d\d?)\s+(\S+)\s+(\S+)/ &&<br>
ProcessHistory("ACL $1 $2","$aclsort","$3","$_")
&& next;<br>
# order extended access-lists<br>
/^access-list\s+(\d\d\d)\s+(\S+)\s+ip\s+host\s+(\S+)/
&&<br>
ProcessHistory("EACL $1 $2","$aclsort","$3","$_")
&& next;<br>
/^access-list\s+(\d\d\d)\s+(\S+)\s+ip\s+(\d\S+)/ &&<br>
ProcessHistory("EACL $1 $2","$aclsort","$3","$_")
&& next;<br>
/^access-list\s+(\d\d\d)\s+(\S+)\s+ip\s+any/ &&<br>
ProcessHistory("EACL $1 $2","$aclsort","0.0.0.0","$_")
&& next;<br>
# order arp lists<br>
/^arp\s+(\d+\.\d+\.\d+\.\d+)\s+/ &&<br>
ProcessHistory("ARP","$aclsort","$1","$_") &&
next;<br>
/^ip(v6)?
prefix-list\s+(\S+)\s+seq\s+(\d+)\s+(permit|deny)\s+(\S+)(\/.*)$/<br>
&& ProcessHistory("PACL $2 $4","$aclsort","$5",<br>
"ip$1 prefix-list $2 $4 $5$6\n")<br>
&& next;<br>
# order logging statements<br>
/^logging (\d+\.\d+\.\d+\.\d+)/ &&<br>
ProcessHistory("LOGGING","ipsort","$1","$_") &&
next;<br>
# order/prune snmp-server host statements<br>
# we only prune lines of the form<br>
# snmp-server host a.b.c.d <community><br>
if (/^snmp-server host (\d+\.\d+\.\d+\.\d+) /) {<br>
if ($filter_commstr) {<br>
my($ip) = $1;<br>
my($line) = "snmp-server host $ip";<br>
my(@tokens) = split(' ', $');<br>
my($token);<br>
while ($token = shift(@tokens)) {<br>
if ($token eq 'version') {<br>
$line .= " " . join(' ', ($token, shift(@tokens)));<br>
if ($token eq '3') {<br>
$line .= " " . join(' ', ($token,
shift(@tokens)));<br>
}<br>
} elsif ($token eq 'vrf') {<br>
$line .= " " . join(' ', ($token, shift(@tokens)));<br>
} elsif ($token =~ /^(informs?|traps?|(no)?auth)$/)
{<br>
$line .= " " . $token;<br>
} else {<br>
$line = "!$line " . join(' ', ("<removed>",<br>
join(' ',@tokens)));<br>
last;<br>
}<br>
}<br>
ProcessHistory("SNMPSERVERHOST","ipsort","$ip","$line\n");<br>
} else {<br>
ProcessHistory("SNMPSERVERHOST","ipsort","$1","$_");<br>
}<br>
next;<br>
}<br>
if (/^(snmp-server community) (\S+)/) {<br>
if ($filter_commstr) {<br>
ProcessHistory("SNMPSERVERCOMM","keysort","$_",<br>
"!$1 <removed>$'") && next;<br>
} else {<br>
ProcessHistory("SNMPSERVERCOMM","keysort","$_","$_")
&& next;<br>
}<br>
}<br>
# prune tacacs/radius server keys<br>
if (/^((tacacs|radius)-server\s(\w*[-\s(\s\S+])*\s?key) (\d
)?\w+/<br>
&& $filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>$'"); next;<br>
}<br>
# order clns host statements<br>
/^clns host \S+ (\S+)/ &&<br>
ProcessHistory("CLNS","keysort","$1","$_") &&
next;<br>
# order alias statements<br>
/^alias / &&
ProcessHistory("ALIAS","keysort","$_","$_") && next;<br>
# delete ntp auth password - this md5 is a reversable too<br>
if (/^(ntp authentication-key \d+ md5) / &&
$filter_pwds >= 1) {<br>
ProcessHistory("","","","!$1 <removed>\n"); next;<br>
}<br>
# order ntp peers/servers<br>
if (/^ntp (server|peer) (\d+)\.(\d+)\.(\d+)\.(\d+)/) {<br>
$sortkey = sprintf("$1 %03d%03d%03d%03d",$2,$3,$4,$5);<br>
ProcessHistory("NTP","keysort",$sortkey,"$_");<br>
next;<br>
}<br>
# order ip host statements<br>
/^ip host (\S+) / &&<br>
ProcessHistory("IPHOST","keysort","$1","$_") &&
next;<br>
# order ip nat source static statements<br>
/^ip nat (\S+) source static (\S+)/ &&<br>
ProcessHistory("IP NAT $1","ipsort","$2","$_")
&& next;<br>
# order atm map-list statements<br>
/^\s+ip\s+(\d+\.\d+\.\d+\.\d+)\s+atm-vc/ &&<br>
ProcessHistory("ATM map-list","ipsort","$1","$_")
&& next;<br>
# order ip rcmd lines<br>
/^ip rcmd/ &&
ProcessHistory("RCMD","keysort","$_","$_") && next;<br>
<br>
# system controller<br>
/^syscon address (\S*) (\S*)/ &&<br>
ProcessHistory("","","","!syscon address $1
<removed>\n") &&<br>
next;<br>
if (/^syscon password (\S*)/ && $filter_pwds >=
1) {<br>
ProcessHistory("","","","!syscon password
<removed>\n");<br>
next;<br>
}<br>
<br>
/^ *Cryptochecksum:/ && next;<br>
<br>
# catch anything that wasnt matched above.<br>
ProcessHistory("","","","$_");<br>
# end of config. the ": " game is for the PIX<br>
#if (/^(: +)?end$/) {<br>
if (/^end$/) {<br>
$found_end = 1;<br>
return(0);<br>
}<br>
}<br>
# The ContentEngine lacks a definitive "end of config"
marker. If we<br>
# know that it is a CE, SAN, or NXOS and we have seen at
least 5 lines<br>
# of write term output, we can be reasonably sure that we
got the config.<br>
if (($type == "CE" || $type == "SAN" || $type == "NXOS" )
&& $linecnt > 5) {<br>
$found_end = 1;<br>
return(0);<br>
}<br>
<br>
return(0);<br>
}<br>
<br>
# dummy function<br>
sub DoNothing {print STDOUT;}<br>
<br>
# Main<br>
@commandtable = (<br>
{'show version' => 'ShowVersion'},<br>
{'show vlan' => 'ShowVLAN'},<br>
{'show running-config' => 'WriteTerm'},<br>
);<br>
# Use an array to preserve the order of the commands and a hash
for mapping<br>
# commands to the subroutine and track commands that have been
completed.<br>
@commands = map(keys(%$_), @commandtable);<br>
%commands = map(%$_, @commandtable);<br>
<br>
$cisco_cmds = join(";",@commands);<br>
$cmds_regexp = join("|", map quotemeta($_), @commands);<br>
<br>
if (length($host) == 0) {<br>
if ($file) {<br>
print(STDERR "Too few arguments: file name required\n");<br>
exit(1);<br>
} else {<br>
print(STDERR "Too few arguments: host name required\n");<br>
exit(1);<br>
}<br>
}<br>
open(OUTPUT,">$host.new") || die "Can't open $host.new for
writing: $!\n";<br>
select(OUTPUT);<br>
# make OUTPUT unbuffered if debugging<br>
if ($debug) { $| = 1; }<br>
<br>
if ($file) {<br>
print STDERR "opening file $host\n" if ($debug);<br>
print STDOUT "opening file $host\n" if ($log);<br>
open(INPUT,"<$host") || die "open failed for $host:
$!\n";<br>
} else {<br>
print STDERR "executing bntlogin -t $timeo -c\"$cisco_cmds\"
$host\n" if ($debug);<br>
print STDOUT "executing bntlogin -t $timeo -c\"$cisco_cmds\"
$host\n" if ($log);<br>
if (defined($ENV{NOPIPE})) {<br>
system "bntlogin -t $timeo -c \"$cisco_cmds\" $host
</dev/null > $host.raw 2>&1" || die "bntlogin
failed for $host: $!\n";<br>
open(INPUT, "< $host.raw") || die "bntlogin failed for
$host: $!\n";<br>
} else {<br>
open(INPUT,"bntlogin -t $timeo -c \"$cisco_cmds\" $host
</dev/null |") || die "bntlogin failed for $host: $!\n";<br>
}<br>
}<br>
<br>
# determine ACL sorting mode<br>
if ($ENV{"ACLSORT"} =~ /no/i) {<br>
$aclsort = "";<br>
}<br>
# determine community string filtering mode<br>
if (defined($ENV{"NOCOMMSTR"}) &&<br>
($ENV{"NOCOMMSTR"} =~ /yes/i || $ENV{"NOCOMMSTR"} =~ /^$/))
{<br>
$filter_commstr = 1;<br>
} else {<br>
$filter_commstr = 0;<br>
}<br>
# determine password filtering mode<br>
if ($ENV{"FILTER_PWDS"} =~ /no/i) {<br>
$filter_pwds = 0;<br>
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {<br>
$filter_pwds = 2;<br>
} else {<br>
$filter_pwds = 1;<br>
}<br>
<br>
#ProcessHistory("","","","!RANCID-CONTENT-TYPE: cisco\n!\n");<br>
ProcessHistory("","","","!RANCID-CONTENT-TYPE: ibmbnt\n!\n");<br>
ProcessHistory("COMMENTS","keysort","B0","!\n");<br>
ProcessHistory("COMMENTS","keysort","D0","!\n");<br>
ProcessHistory("COMMENTS","keysort","F0","!\n");<br>
ProcessHistory("COMMENTS","keysort","G0","!\n");<br>
TOP: while(<INPUT>) {<br>
tr/\015//d;<br>
if (/[>#]\s?exit/) {<br>
$clean_run = 1;<br>
last;<br>
}<br>
if (/^Error:/) {<br>
print STDOUT ("$host bntlogin error: $_");<br>
print STDERR ("$host bntlogin error: $_") if ($debug);<br>
$clean_run = 0;<br>
last;<br>
}<br>
while (/[>#]\s*($cmds_regexp)\s*$/) {<br>
$cmd = $1;<br>
if (!defined($prompt)) {<br>
$prompt = ($_ =~ /^([^#>]+[#>])/)[0];<br>
$prompt =~ s/([][}{)(\\])/\\$1/g;<br>
print STDERR ("PROMPT MATCH: $prompt\n") if ($debug);<br>
}<br>
print STDERR ("HIT COMMAND:$_") if ($debug);<br>
if (! defined($commands{$cmd})) {<br>
print STDERR "$host: found unexpected command -
\"$cmd\"\n";<br>
$clean_run = 0;<br>
last TOP;<br>
}<br>
$rval = &{$commands{$cmd}};<br>
delete($commands{$cmd});<br>
if ($rval == -1) {<br>
$clean_run = 0;<br>
last TOP;<br>
}<br>
}<br>
}<br>
print STDOUT "Done $logincmd: $_\n" if ($log);<br>
# Flush History<br>
ProcessHistory("","","","");<br>
# Cleanup<br>
close(INPUT);<br>
close(OUTPUT);<br>
<br>
if (defined($ENV{NOPIPE})) {<br>
unlink("$host.raw") if (! $debug);<br>
}<br>
<br>
# check for completeness<br>
if (scalar(%commands) || !$clean_run || !$found_end) {<br>
if (scalar(%commands)) {<br>
printf(STDOUT "$host: missed cmd(s): %s\n", join(',',
keys(%commands)));<br>
printf(STDERR "$host: missed cmd(s): %s\n", join(',',
keys(%commands))) if ($debug);<br>
}<br>
if (!$clean_run || !$found_end) {<br>
print STDOUT "$host: End of run not found\n";<br>
print STDERR "$host: End of run not found\n" if ($debug);<br>
system("/usr/bin/tail -1 $host.new");<br>
}<br>
unlink "$host.new" if (! $debug);<br>
}<br>
<br>
<br>
new file in $rancid-home/bin : bntlogin with 755<br>
<br>
<br>
<br>
#! /usr/bin/expect --<br>
##<br>
## $Id: clogin.in 2255 2010-10-06 20:31:24Z heas $<br>
##<br>
## rancid 2.3.6<br>
## Copyright (c) 1997-2009 by Terrapin Communications, Inc.<br>
## All rights reserved.<br>
##<br>
## This code is derived from software contributed to and
maintained by<br>
## Terrapin Communications, Inc. by Henry Kilmer, John Heasley,
Andrew Partan,<br>
## Pete Whiting, Austin Schutz, and Andrew Fort.<br>
##<br>
## Redistribution and use in source and binary forms, with or
without<br>
## modification, are permitted provided that the following
conditions<br>
## are met:<br>
## 1. Redistributions of source code must retain the above
copyright<br>
## notice, this list of conditions and the following
disclaimer.<br>
## 2. Redistributions in binary form must reproduce the above
copyright<br>
## notice, this list of conditions and the following
disclaimer in the<br>
## documentation and/or other materials provided with the
distribution.<br>
## 3. All advertising materials mentioning features or use of
this software<br>
## must display the following acknowledgement:<br>
## This product includes software developed by Terrapin
Communications,<br>
## Inc. and its contributors for RANCID.<br>
## 4. Neither the name of Terrapin Communications, Inc. nor the
names of its<br>
## contributors may be used to endorse or promote products
derived from<br>
## this software without specific prior written permission.<br>
## 5. It is requested that non-binding fixes and modifications
be contributed<br>
## back to Terrapin Communications, Inc.<br>
##<br>
## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC.
AND CONTRIBUTORS<br>
## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED<br>
## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR<br>
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COMPANY OR
CONTRIBUTORS<br>
## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR<br>
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF<br>
## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS<br>
## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN<br>
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE)<br>
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE<br>
## POSSIBILITY OF SUCH DAMAGE.<br>
# <br>
# The expect login scripts were based on Erik Sherk's gwtn, by
permission.<br>
# <br>
# clogin - Cisco login<br>
#<br>
# Most options are intuitive for logging into a Cisco router.<br>
# The default is to enable (thus -noenable). Some folks have<br>
# setup tacacs to have a user login at priv-lvl = 15 (enabled)<br>
# so the -autoenable flag was added for this case (don't go
through<br>
# the process of enabling and the prompt will be the "#" prompt.<br>
# The default username password is the same as the vty password.<br>
#<br>
<br>
# Usage line<br>
set usage "Usage: $argv0 \[-dSV\] \[-autoenable\] \[-noenable\]
\[-c command\] \<br>
\[-Evar=x\] \[-e enable-password\] \[-f cloginrc-file\] \[-p
user-password\] \<br>
\[-r passphrase\] \[-s script-file\] \[-t timeout\] \[-u
username\] \<br>
\[-v vty-password\] \[-w enable-username\] \[-x command-file\] \<br>
\[-y ssh_cypher_type\] router \[router...\]\n"<br>
<br>
# env(CLOGIN) may contain:<br>
# x == do not set xterm banner or name<br>
<br>
# Password file<br>
set password_file $env(HOME)/.cloginrc<br>
# Default is to login to the router<br>
set do_command 0<br>
set do_script 0<br>
# The default is to automatically enable<br>
set avenable 1<br>
# The default is that you login non-enabled (tacacs can have you
login already<br>
# enabled)<br>
set avautoenable 0<br>
# The default is to look in the password file to find the
passwords. This<br>
# tracks if we receive them on the command line.<br>
set do_passwd 1<br>
set do_enapasswd 1<br>
# Save config, if prompted<br>
set do_saveconfig 0<br>
# Sometimes routers take awhile to answer (the default is 10
sec)<br>
set timeoutdflt 45<br>
#<br>
set send_human {.4 .4 .7 .3 5}<br>
# new option to provide "login" command capabilities<br>
set loginonly 0<br>
<br>
# Find the user in the ENV, or use the unix userid.<br>
if {[ info exists env(CISCO_USER) ]} {<br>
set default_user $env(CISCO_USER)<br>
} elseif {[ info exists env(USER) ]} {<br>
set default_user $env(USER)<br>
} elseif {[ info exists env(LOGNAME) ]} {<br>
set default_user $env(LOGNAME)<br>
} else {<br>
# This uses "id" which I think is portable. At least it has
existed<br>
# (without options) on all machines/OSes I've been on
recently -<br>
# unlike whoami or id -nu.<br>
if [ catch {exec id} reason ] {<br>
send_error "\nError: could not exec id: $reason\n"<br>
exit 1<br>
}<br>
regexp {\(([^)]*)} "$reason" junk default_user<br>
}<br>
if {[ info exists env(CLOGINRC) ]} {<br>
set password_file $env(CLOGINRC)<br>
}<br>
<br>
# Process the command line<br>
for {set i 0} {$i < $argc} {incr i} {<br>
set arg [lindex $argv $i]<br>
<br>
switch -glob -- $arg {<br>
# Expect debug mode<br>
-d* {<br>
exp_internal 1<br>
# Username<br>
} -u* {<br>
if {! [regexp .\[uU\](.+) $arg ignore user]} {<br>
incr i<br>
set username [ lindex $argv $i ]<br>
}<br>
# VTY Password<br>
} -p* {<br>
if {! [regexp .\[pP\](.+) $arg ignore userpasswd]} {<br>
incr i<br>
set userpasswd [ lindex $argv $i ]<br>
}<br>
set do_passwd 0<br>
# ssh passphrase<br>
} -r* {<br>
if {! [ regexp .\[rR\](.+) $arg ignore passphrase]} {<br>
incr i<br>
set vapassphrase [ lindex $argv $i ]<br>
}<br>
# VTY Password<br>
} -v* {<br>
if {! [regexp .\[vV\](.+) $arg ignore passwd]} {<br>
incr i<br>
set passwd [ lindex $argv $i ]<br>
}<br>
set do_passwd 0<br>
# Version string<br>
} -V* {<br>
send_user "rancid 2.3.6\n"<br>
exit 0<br>
# Enable Username<br>
} -w* {<br>
if {! [regexp .\[wW\](.+) $arg ignore enauser]} {<br>
incr i<br>
set enausername [ lindex $argv $i ]<br>
}<br>
# Environment variable to pass to -s scripts<br>
} -E* {<br>
if {[regexp .\[E\](.+)=(.+) $arg ignore varname
varvalue]} {<br>
set E$varname $varvalue<br>
} else {<br>
send_user "\nError: invalid format for -E in $arg\n"<br>
exit 1<br>
}<br>
# Enable Password<br>
} -e* {<br>
if {! [regexp .\[e\](.+) $arg ignore enapasswd]} {<br>
incr i<br>
set enapasswd [ lindex $argv $i ]<br>
}<br>
set do_enapasswd 0<br>
# Command to run.<br>
} -c* {<br>
if {! [regexp .\[cC\](.+) $arg ignore command]} {<br>
incr i<br>
set command [ lindex $argv $i ]<br>
}<br>
set do_command 1<br>
# Expect script to run.<br>
} -s* {<br>
if {! [regexp .\[sS\](.+) $arg ignore sfile]} {<br>
incr i<br>
set sfile [ lindex $argv $i ]<br>
}<br>
if { ! [ file readable $sfile ] } {<br>
send_user "\nError: Can't read $sfile\n"<br>
exit 1<br>
}<br>
set do_script 1<br>
# save config on exit<br>
} -S* {<br>
set do_saveconfig 1<br>
# 'ssh -c' cypher type<br>
} -y* {<br>
if {! [regexp .\[eE\](.+) $arg ignore cypher]} {<br>
incr i<br>
set cypher [ lindex $argv $i ]<br>
}<br>
# alternate cloginrc file<br>
} -f* {<br>
if {! [regexp .\[fF\](.+) $arg ignore password_file]} {<br>
incr i<br>
set password_file [ lindex $argv $i ]<br>
}<br>
# Timeout<br>
} -t* {<br>
if {! [regexp .\[tT\](.+) $arg ignore timeout]} {<br>
incr i<br>
set timeoutdflt [ lindex $argv $i ]<br>
}<br>
# Command file<br>
} -x* {<br>
if {! [regexp .\[xX\](.+) $arg ignore cmd_file]} {<br>
incr i<br>
set cmd_file [ lindex $argv $i ]<br>
}<br>
if [ catch {set cmd_fd [open $cmd_file r]} reason ] {<br>
send_user "\nError: $reason\n"<br>
exit 1<br>
}<br>
set cmd_text [read $cmd_fd]<br>
close $cmd_fd<br>
set command [join [split $cmd_text \n] \;]<br>
set do_command 1<br>
# Do we enable?<br>
} -noenable {<br>
set avenable 0<br>
# Does tacacs automatically enable us?<br>
} -autoenable {<br>
set avautoenable 1<br>
set avenable 0<br>
} -* {<br>
send_user "\nError: Unknown argument! $arg\n"<br>
send_user $usage<br>
exit 1<br>
} default {<br>
break<br>
}<br>
}<br>
}<br>
# Process routers...no routers listed is an error.<br>
if { $i == $argc } {<br>
send_user "\nError: $usage"<br>
}<br>
<br>
# Only be quiet if we are running a script (it can log its
output<br>
# on its own)<br>
if { $do_script } {<br>
log_user 0<br>
} else {<br>
log_user 1<br>
}<br>
<br>
#<br>
# Done configuration/variable setting. Now run with it...<br>
#<br>
<br>
# Sets Xterm title if interactive...if its an xterm and the user
cares<br>
proc label { host } {<br>
global env<br>
# if CLOGIN has an 'x' in it, don't set the xterm
name/banner<br>
if [info exists env(CLOGIN)] {<br>
if {[string first "x" $env(CLOGIN)] != -1} { return }<br>
}<br>
# take host from ENV(TERM)<br>
if [info exists env(TERM)] {<br>
if [ regexp \^(xterm|vs) $env(TERM) ignore ] {<br>
send_user "\033]1;[lindex [split $host "."] 0]\a"<br>
send_user "\033]2;$host\a"<br>
}<br>
}<br>
}<br>
<br>
# This is a helper function to make the password file easier to<br>
# maintain. Using this the password file has the form:<br>
# add password sl* pete cow<br>
# add password at* steve<br>
# add password * hanky-pie<br>
proc add {var args} { global int_$var ; lappend int_$var $args}<br>
proc include {args} {<br>
global env<br>
regsub -all "(^{|}$)" $args {} args<br>
if { [ regexp "^/" $args ignore ] == 0 } {<br>
set args $env(HOME)/$args<br>
}<br>
source_password_file $args<br>
}<br>
<br>
proc find {var router} {<br>
upvar int_$var list<br>
if { [info exists list] } {<br>
foreach line $list {<br>
if { [string match [lindex $line 0] $router ] } {<br>
return [lrange $line 1 end]<br>
}<br>
}<br>
}<br>
return {}<br>
}<br>
<br>
# Loads the password file. Note that as this file is tcl, and
that<br>
# it is sourced, the user better know what to put in there, as
it<br>
# could install more than just password info... I will assume
however,<br>
# that a "bad guy" could just as easy put such code in the
clogin<br>
# script, so I will leave .cloginrc as just an extention of that
script<br>
proc source_password_file { password_file } {<br>
global env<br>
if { ! [file exists $password_file] } {<br>
send_user "\nError: password file ($password_file) does not
exist\n"<br>
exit 1<br>
}<br>
file stat $password_file fileinfo<br>
if { [expr ($fileinfo(mode) & 007)] != 0000 } {<br>
send_user "\nError: $password_file must not be world
readable/writable\n"<br>
exit 1<br>
}<br>
if [ catch {source $password_file} reason ] {<br>
send_user "\nError: $reason\n"<br>
exit 1<br>
}<br>
}<br>
<br>
# Log into the router.<br>
# returns: 0 on success, 1 on failure, -1 if rsh was used
successfully<br>
proc login { router user userpswd passwd enapasswd cmethod
cyphertype identfile } {<br>
global command spawn_id in_proc do_command do_script
platform passphrase<br>
global prompt prompt_match u_prompt p_prompt e_prompt sshcmd<br>
set in_proc 1<br>
set uprompt_seen 0<br>
<br>
# try each of the connection methods in $cmethod until one
is successful<br>
set progs [llength $cmethod]<br>
foreach prog [lrange $cmethod 0 end] {<br>
incr progs -1<br>
if [string match "telnet*" $prog] {<br>
regexp {telnet(:([^[:space:]]+))*} $prog methcmd suffix
port<br>
if {"$port" == ""} {<br>
set retval [ catch {spawn telnet $router} reason ]<br>
} else {<br>
set retval [ catch {spawn telnet $router $port} reason ]<br>
}<br>
if { $retval } {<br>
send_user "\nError: telnet failed: $reason\n"<br>
return 1<br>
}<br>
} elseif [string match "ssh*" $prog] {<br>
# ssh to the router & try to login with or without
an identfile.<br>
regexp {ssh(:([^[:space:]]+))*} $prog methcmd suffix
port<br>
set cmd [join [lindex $sshcmd 0] " "]<br>
if {"$port" != ""} {<br>
set cmd "$cmd -p $port"<br>
}<br>
if {"$identfile" != ""} {<br>
set cmd "$cmd -i $identfile"<br>
}<br>
set retval [ catch {eval spawn [split "$cmd -c
$cyphertype -x -l $user $router" { }]} reason ]<br>
if { $retval } {<br>
send_user "\nError: $sshcmd failed: $reason\n"<br>
return 1<br>
}<br>
} elseif ![string compare $prog "rsh"] {<br>
if { ! $do_command } {<br>
if { [llength $cmethod] == 1 } {<br>
send_user "\nError: rsh is an invalid method for -x
and "<br>
send_user "interactive logins\n"<br>
}<br>
if { $progs == 0 } {<br>
return 1<br>
}<br>
continue;<br>
}<br>
<br>
set commands [split $command \;]<br>
set num_commands [llength $commands]<br>
set rshfail 0<br>
for {set i 0} {$i < $num_commands &&
!$rshfail} { incr i} {<br>
log_user 0<br>
set retval [ catch {spawn rsh $user@$router [lindex
$commands $i] } reason ]<br>
if { $retval } {<br>
send_user "\nError: rsh failed: $reason\n"<br>
log_user 1; return 1<br>
}<br>
send_user "$router# [lindex $commands $i]\n"<br>
<br>
# rcmd does not get a pager and no prompts, so we just
have to<br>
# look for failures & lines.<br>
expect {<br>
"Connection refused" { catch {close}; catch {wait};<br>
send_user "\nError: Connection\<br>
Refused ($prog): $router\n"<br>
set rshfail 1<br>
}<br>
-re "(Connection closed by|Connection to \[^\n\r]+
closed)" {<br>
catch {close}; catch {wait};<br>
send_user "\nError: Connection\<br>
closed ($prog): $router\n"<br>
set rshfail 1<br>
}<br>
"Host is unreachable" { catch {close}; catch
{wait};<br>
send_user "\nError: Host Unreachable:\<br>
$router\n"<br>
set rshfail 1<br>
}<br>
"No address associated with" {<br>
catch {close}; catch {wait};<br>
send_user "\nError: Unknown host\<br>
$router\n"<br>
set rshfail 1<br>
}<br>
-re "\b+" { exp_continue }<br>
-re "\[\n\r]+" { send_user -- "$expect_out(buffer)"<br>
exp_continue<br>
}<br>
timeout { catch {close}; catch {wait};<br>
send_user "\nError: TIMEOUT reached\n"<br>
set rshfail 1<br>
}<br>
eof { catch {close}; catch {wait}; }<br>
}<br>
log_user 1<br>
}<br>
if { $rshfail } {<br>
if { !$progs } {<br>
return 1<br>
} else {<br>
continue<br>
}<br>
}<br>
# fake the end of the session for rancid.<br>
send_user "$router# exit\n"<br>
# return rsh "success"<br>
return -1<br>
} else {<br>
send_user "\nError: unknown connection method: $prog\n"<br>
return 1<br>
}<br>
sleep 0.3<br>
<br>
# This helps cleanup each expect clause.<br>
expect_after {<br>
timeout {<br>
send_user "\nError: TIMEOUT reached\n"<br>
catch {close}; catch {wait};<br>
if { $in_proc} {<br>
return 1<br>
} else {<br>
continue<br>
}<br>
} eof {<br>
send_user "\nError: EOF received\n"<br>
catch {close}; catch {wait};<br>
if { $in_proc} {<br>
return 1<br>
} else {<br>
continue<br>
}<br>
}<br>
}<br>
<br>
# Here we get a little tricky. There are several
possibilities:<br>
# the router can ask for a username and passwd and then<br>
# talk to the TACACS server to authenticate you, or if the<br>
# TACACS server is not working, then it will use the enable<br>
# passwd. Or, the router might not have TACACS turned on,<br>
# then it will just send the passwd.<br>
# if telnet fails with connection refused, try ssh<br>
expect {<br>
-re "(Connection refused|Secure connection \[^\n\r]+
refused)" {<br>
catch {close}; catch {wait};<br>
if !$progs {<br>
send_user "\nError: Connection Refused ($prog):
$router\n"<br>
return 1<br>
}<br>
}<br>
-re "(Connection closed by|Connection to \[^\n\r]+ closed)"
{<br>
catch {close}; catch {wait};<br>
if !$progs {<br>
send_user "\nError: Connection closed ($prog):
$router\n"<br>
return 1<br>
}<br>
}<br>
eof { send_user "\nError: Couldn't login: $router\n"; wait;
return 1 }<br>
-nocase "unknown host\r" {<br>
send_user "\nError: Unknown host $router\n";<br>
catch {close}; catch {wait};<br>
return 1<br>
}<br>
"Host is unreachable" {<br>
send_user "\nError: Host Unreachable: $router\n";<br>
catch {close}; catch {wait};<br>
return 1<br>
}<br>
"No address associated with name" {<br>
send_user "\nError: Unknown host $router\n";<br>
catch {close}; catch {wait};<br>
return 1<br>
}<br>
-re "(Host key not found |The authenticity of host .* be
established).*\(yes\/no\)\?" {<br>
send "yes\r"<br>
send_user "\nHost $router added to the list of known
hosts.\n"<br>
exp_continue<br>
}<br>
-re "HOST IDENTIFICATION HAS CHANGED.* \(yes\/no\)\?" {<br>
send "no\r"<br>
send_user "\nError: The host key for $router has
changed. Update the SSH known_hosts file accordingly.\n"<br>
catch {close}; catch {wait};<br>
return 1<br>
}<br>
-re "Offending key for .* \(yes\/no\)\?" {<br>
send "no\r"<br>
send_user "\nError: host key mismatch for $router.
Update the SSH known_hosts file accordingly.\n"<br>
catch {close}; catch {wait};<br>
return 1<br>
}<br>
-re "(denied|Sorry)" {<br>
send_user "\nError: Check your passwd for
$router\n"<br>
catch {close}; catch {wait}; return 1<br>
}<br>
"Login failed" {<br>
send_user "\nError: Check your passwd for
$router\n"<br>
catch {close}; catch {wait}; return 1<br>
}<br>
-re "% (Bad passwords|Authentication failed)" {<br>
send_user "\nError: Check your passwd for
$router\n"<br>
catch {close}; catch {wait}; return 1<br>
}<br>
"Press any key to continue" {<br>
# send_user "Pressing the ANY key\n"<br>
send "\r"<br>
exp_continue<br>
}<br>
-re "Enter Selection: " {<br>
# Catalyst 1900s have some lame menu. Enter<br>
# K to reach a command-line.<br>
send "K\r"<br>
exp_continue<br>
}<br>
-re "Last login:" {<br>
exp_continue<br>
}<br>
-re "@\[^\r\n]+ $p_prompt" {<br>
# ssh pwd prompt<br>
sleep 1<br>
send -- "$userpswd\r"<br>
exp_continue<br>
}<br>
-re "Enter passphrase.*: " {<br>
# sleep briefly to allow time for stty -echo<br>
sleep .3<br>
send -- "$passphrase\r"<br>
exp_continue<br>
}<br>
-re "$u_prompt" {<br>
send -- "$user\r"<br>
set uprompt_seen 1<br>
exp_continue<br>
}<br>
-re "$p_prompt" {<br>
sleep 1<br>
if {$uprompt_seen == 1} {<br>
send -- "$userpswd\r"<br>
} else {<br>
send -- "$passwd\r"<br>
}<br>
exp_continue<br>
}<br>
-re "$prompt" {<br>
set prompt_match $expect_out(0,string);<br>
break;<br>
}<br>
"Login invalid" {<br>
send_user "\nError: Invalid login: $router\n";<br>
catch {close}; catch {wait}; return 1<br>
}<br>
}<br>
}<br>
<br>
set in_proc 0<br>
return 0<br>
}<br>
<br>
# New subroutine to provide "login" command capabilities, using
the enable user and enable password<br>
# Login<br>
proc do_login { enauser enapasswd } {<br>
global prompt in_proc<br>
global u_prompt e_prompt<br>
set in_proc 1<br>
<br>
send "login\r"<br>
expect {<br>
-re "$u_prompt" { send "$enauser\r"; exp_continue}<br>
-re "$e_prompt" { send "$enapasswd\r"; exp_continue}<br>
"#" { set prompt "#" }<br>
"(login)" { set prompt "> (login) " }<br>
-re "(denied|Sorry|Incorrect)" {<br>
# % Access denied - from local auth and
poss. others<br>
send_user "\nError: Check your Login
passwd\n";<br>
return 1<br>
}<br>
"% Error in authentication" {<br>
send_user "\nError: Check your Login
passwd\n"<br>
return 1<br>
}<br>
"% Bad passwords" {<br>
send_user "\nError: Check your Login
passwd\n"<br>
return 1<br>
}<br>
}<br>
# We set the prompt variable (above) so script files don't
need<br>
# to know what it is.<br>
set in_proc 0<br>
return 0<br>
}<br>
<br>
# Enable<br>
proc do_enable { enauser enapasswd } {<br>
global do_saveconfig in_proc<br>
global prompt u_prompt e_prompt<br>
set in_proc 1<br>
<br>
send "enable\r"<br>
expect {<br>
-re "$u_prompt" { send -- "$enauser\r"; exp_continue}<br>
-re "$e_prompt" { send -- "$enapasswd\r"; exp_continue}<br>
"#" { set prompt "#" }<br>
"(enable)" { set prompt "> \\(enable\\) " }<br>
-re "(denied|Sorry|Incorrect)" {<br>
# % Access denied - from local auth and poss.
others<br>
send_user "\nError: Check your Enable passwd\n";<br>
return 1<br>
}<br>
"% Error in authentication" {<br>
send_user "\nError: Check your Enable passwd\n"<br>
return 1<br>
}<br>
"% Bad passwords" {<br>
send_user "\nError: Check your Enable passwd\n"<br>
return 1<br>
}<br>
}<br>
# We set the prompt variable (above) so script files don't
need<br>
# to know what it is.<br>
set in_proc 0<br>
return 0<br>
}<br>
<br>
# Run commands given on the command line.<br>
proc run_commands { prompt command } {<br>
global do_saveconfig in_proc platform<br>
set in_proc 1<br>
<br>
# If the prompt is (enable), then we are on a switch and the<br>
# command is "set length 0"; otherwise its "terminal length
0".<br>
# skip if its an extreme (since the pager can not be
disabled on a<br>
# per-vty basis).<br>
if { [ string compare "extreme" "$platform" ] } {<br>
if [ regexp -- ".*> .*enable" "$prompt" ] {<br>
send "set length 0\r"<br>
# This is ugly, but reduces code duplication, allowing
the<br>
# subsequent expects to handle everything as normal.<br>
set command "set logging session disable;$command"<br>
} else {<br>
send "terminal-length 0\r"<br>
}<br>
# match cisco config mode prompts too, such as
router(config-if)#,<br>
# but catalyst does not change in this fashion.<br>
regsub -all {^(.{1,11}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt<br>
expect {<br>
-re $reprompt {}<br>
-re "\[\n\r]+" { exp_continue }<br>
}<br>
} else {<br>
set reprompt $prompt<br>
}<br>
<br>
# this is the only way i see to get rid of more prompts in
o/p..grrrrr<br>
log_user 0<br>
<br>
set commands [split $command \;]<br>
set num_commands [llength $commands]<br>
# the pager can not be turned off on the PIX, so we have to
look<br>
# for the "More" prompt. the extreme is equally obnoxious,
with a<br>
# global switch in the config.<br>
for {set i 0} {$i < $num_commands} { incr i} {<br>
send -- "[subst -nocommands [lindex $commands $i]]\r"<br>
expect {<br>
-re "\b+" { exp_continue }<br>
-re "^\[^\n\r *]*$reprompt" { send_user --
"$expect_out(buffer)"<br>
}<br>
-re "^\[^\n\r]*$reprompt." { send_user --
"$expect_out(buffer)"<br>
exp_continue<br>
}<br>
-re "^--More--\[\r\n]+" { # specific match c1900
pager<br>
send " "<br>
exp_continue<br>
}<br>
-re "\[\n\r]+" { send_user --
"$expect_out(buffer)"<br>
exp_continue<br>
}<br>
-re "\[^\r\n]*Press <SPACE> to cont\[^\r\n]*" {<br>
send " "<br>
# bloody ^[[2K after " "<br>
expect {<br>
-re "^\[^\r\n]*\r" {}<br>
}<br>
exp_continue<br>
}<br>
-re "^ *--More--\[^\n\r]*" {<br>
send " "<br>
exp_continue }<br>
-re "^<-+ More -+>\[^\n\r]*" {<br>
send_user -- "$expect_out(buffer)"<br>
send " "<br>
exp_continue }<br>
}<br>
}<br>
log_user 1<br>
<br>
if { [ string compare "extreme" "$platform" ] } {<br>
send -h "exit\r"<br>
} else {<br>
send -h "quit\r"<br>
}<br>
expect {<br>
-re "^\[^\n\r *]*$reprompt" {<br>
# the Cisco CE and Jnx ERX<br>
# return to non-enabled mode<br>
# on exit in enabled mode.<br>
send -h "exit\r"<br>
exp_continue;<br>
}<br>
"The system has unsaved changes" { # Force10 SFTOS<br>
if {$do_saveconfig} {<br>
catch {send "y\r"}<br>
} else {<br>
catch {send "n\r"}<br>
}<br>
exp_continue<br>
}<br>
"Would you like to save them now" { # Force10<br>
if {$do_saveconfig} {<br>
catch {send "y\r"}<br>
} else {<br>
catch {send "n\r"}<br>
}<br>
exp_continue<br>
}<br>
-re "(Profile|Configuration) changes have occurred.*" {<br>
# Cisco CSS<br>
if {$do_saveconfig} {<br>
catch {send "y\r"}<br>
} else {<br>
catch {send "n\r"}<br>
}<br>
exp_continue<br>
}<br>
"Do you wish to save your configuration changes" {<br>
if {$do_saveconfig} {<br>
catch {send "y\r"}<br>
} else {<br>
catch {send "n\r"}<br>
}<br>
exp_continue<br>
}<br>
-re "\[\n\r]+" { exp_continue }<br>
timeout { catch {close}; catch {wait};<br>
return 0<br>
}<br>
eof { return 0 }<br>
}<br>
set in_proc 0<br>
}<br>
<br>
#<br>
# For each router... (this is main loop)<br>
#<br>
source_password_file $password_file<br>
set in_proc 0<br>
set exitval 0<br>
set prompt_match ""<br>
set enable 0<br>
foreach router [lrange $argv $i end] {<br>
set router [string tolower $router]<br>
# attempt at platform switching.<br>
set platform ""<br>
send_user -- "$router\n"<br>
<br>
# device timeout<br>
set timeout [find timeout $router]<br>
if { [llength $timeout] == 0 } {<br>
set timeout $timeoutdflt<br>
}<br>
<br>
# Default prompt.<br>
set prompt "(>|#| \\(enable\\))"<br>
<br>
# If a "login" option is used, no "enable" will be required<br>
# look for login option in .cloginrc<br>
if { [find login $router] != "" } {<br>
set enable 0<br>
set loginonly 1<br>
}<br>
<br>
# look for noenable option in .cloginrc<br>
if { [find noenable $router] == "1" } {<br>
set enable 0<br>
}<br>
<br>
# Figure out passwords<br>
if { $do_passwd || $do_enapasswd } {<br>
set pswd [find password $router]<br>
if { [llength $pswd] == 0 } {<br>
send_user -- "\nError: no password for $router in
$password_file.\n"<br>
continue<br>
}<br>
if { $enable && $do_enapasswd &&
$autoenable == 0 && [llength $pswd] < 2 } {<br>
send_user -- "\nError: no enable password for $router in
$password_file.\n"<br>
continue<br>
}<br>
set passwd [join [lindex $pswd 0] ""]<br>
set enapasswd [join [lindex $pswd 1] ""]<br>
} else {<br>
set passwd $userpasswd<br>
set enapasswd $enapasswd<br>
}<br>
<br>
# Figure out username<br>
if {[info exists username]} {<br>
# command line username<br>
set ruser $username<br>
} else {<br>
set ruser [join [find user $router] ""]<br>
if { "$ruser" == "" } { set ruser $default_user }<br>
}<br>
<br>
# Figure out username's password (if different from the vty
password)<br>
if {[info exists userpasswd]} {<br>
# command line username<br>
set userpswd $userpasswd<br>
} else {<br>
set userpswd [join [find userpassword $router] ""]<br>
if { "$userpswd" == "" } { set userpswd $passwd }<br>
}<br>
<br>
# Figure out enable username<br>
if {[info exists enausername]} {<br>
# command line enausername<br>
set enauser $enausername<br>
} else {<br>
set enauser [join [find enauser $router] ""]<br>
if { "$enauser" == "" } { set enauser $ruser }<br>
}<br>
<br>
# Figure out prompts<br>
set u_prompt [find userprompt $router]<br>
if { "$u_prompt" == "" } {<br>
set u_prompt "(Username|Login|login|user name|User):"<br>
} else {<br>
set u_prompt [join [lindex $u_prompt 0] ""]<br>
}<br>
set p_prompt [find passprompt $router]<br>
if { "$p_prompt" == "" } {<br>
set p_prompt "(\[Pp]assword|passwd|Enter password for \[^
:]+):"<br>
} else {<br>
set p_prompt [join [lindex $p_prompt 0] ""]<br>
}<br>
set e_prompt [find enableprompt $router]<br>
if { "$e_prompt" == "" } {<br>
set e_prompt "\[Pp]assword:"<br>
} else {<br>
set e_prompt [join [lindex $e_prompt 0] ""]<br>
}<br>
<br>
# Figure out identity file to use<br>
set identfile [join [lindex [find identity $router] 0] ""]<br>
<br>
# Figure out passphrase to use<br>
if {[info exists avpassphrase]} {<br>
set passphrase $avpassphrase<br>
} else {<br>
set passphrase [join [lindex [find passphrase $router] 0]
""]<br>
}<br>
if { ! [string length "$passphrase"]} {<br>
set passphrase $passwd<br>
}<br>
<br>
# Figure out cypher type<br>
if {[info exists cypher]} {<br>
# command line cypher type<br>
set cyphertype $cypher<br>
} else {<br>
set cyphertype [find cyphertype $router]<br>
if { "$cyphertype" == "" } { set cyphertype "3des" }<br>
}<br>
<br>
# Figure out connection method<br>
set cmethod [find method $router]<br>
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }<br>
<br>
# Figure out the SSH executable name<br>
set sshcmd [find sshcmd $router]<br>
if { "$sshcmd" == "" } { set sshcmd {ssh} }<br>
<br>
# Login to the router<br>
if {[login $router $ruser $userpswd $passwd $enapasswd
$cmethod $cyphertype $identfile]} {<br>
incr exitval<br>
# if login failed or rsh was unsuccessful, move on to the
next device<br>
continue<br>
}<br>
# Figure out the prompt.<br>
if { [regexp -- "(#| \\(enable\\))" $prompt_match junk] == 1
} {<br>
set enable 0<br>
} else {<br>
if { $avenable == 0 } {<br>
set enable 0<br>
} else {<br>
set ne [find noenable $router]<br>
set ae [find autoenable $router]<br>
if { "$ne" == "1" || "$ae" == "1" || $avautoenable } {<br>
set enable 0<br>
} else {<br>
set enable 1<br>
}<br>
}<br>
}<br>
<br>
# login required?<br>
if { $loginonly } {<br>
if {[do_login $enauser $enapasswd]} {<br>
if { $do_command || $do_script } {<br>
close; wait<br>
continue<br>
}<br>
}<br>
}<br>
<br>
if { $enable } {<br>
if {[do_enable $enauser $enapasswd]} {<br>
if { $do_command || $do_script } {<br>
incr exitval<br>
catch {close}; catch {wait};<br>
continue<br>
}<br>
}<br>
}<br>
<br>
# we are logged in, now figure out the full prompt<br>
send "\r"<br>
expect {<br>
-re "\[\r\n]+" { exp_continue; }<br>
-re "^(.+\[:.])1 ($prompt)" { # stoopid extreme cmd-line
numbers and<br>
# prompt based on state of config changes,<br>
# which may have an * at the beginning.<br>
set junk $expect_out(1,string)<br>
regsub -all "^\\\* " $expect_out(1,string) {}
junk<br>
regsub -all "\[\]\[\(\)]" $junk {\\&}
junk;<br>
set prompt ".? ?$junk\[0-9]+
$expect_out(2,string)";<br>
set platform "extreme"<br>
}<br>
-re "^.+$prompt" { set junk $expect_out(0,string);<br>
regsub -all "\[\]\[\(\)]" $junk {\\&}
prompt;<br>
}<br>
}<br>
<br>
if { $do_command } {<br>
if {[run_commands $prompt $command]} {<br>
incr exitval<br>
continue<br>
}<br>
} elseif { $do_script } {<br>
# If the prompt is (enable), then we are on a switch and the<br>
# command is "set length 0"; otherwise its "terminal length
0".<br>
if [ regexp -- ".*> .*enable" "$prompt" ] {<br>
send "set length 0\r"<br>
expect -re $prompt {}<br>
send "set width 80\r"<br>
expect -re $prompt {}<br>
send "set logging session disable\r"<br>
} else {<br>
send "terminal-length 0\r"<br>
expect -re $prompt {}<br>
send "terminal width 80\r"<br>
}<br>
expect -re $prompt {}<br>
source $sfile<br>
catch {close};<br>
} else {<br>
label $router<br>
log_user 1<br>
interact<br>
}<br>
<br>
# End of for each router<br>
catch {wait};<br>
sleep 0.3<br>
}<br>
exit $exitval<br>
<br>
<br>
And in .cloginrc<br>
<br>
#Auth method is radius.<br>
add method x.y.z.t {your protocol}<br>
add user x.y.z.t {your user}<br>
add userprompt x.y.z.t {"Enter\ radius\ username:"}<br>
add passprompt x.y.z.T {"Enter\ radius\ password:"}<br>
add password x.y.z.t {your password}<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</font>
<div class="moz-signature">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Signature de Alexandre AMSALEG</title>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #666;
}
a:link {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #666666;
text-decoration: none;
}
a:visited {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-decoration: none;
color: #666666;
}
a:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-decoration: none;
color: #666666;
}
a:active {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-decoration: none;
color: #666666;
}
.bleu {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #70B9E2;
}
</style><br>
</div>
Le 19/02/14 12:40, David Gomez a écrit :<br>
</div>
<blockquote cite="mid:53049842.1010406@grupoversia.com" type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
Hi,<br>
<br>
Does anyone knows how to get the running config of this devices
with Rancid?<br>
<br>
IBM Networking Operating System RackSwitch G8124-E<br>
<br>
Greetings!<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 10">
<meta name="Originator" content="Microsoft Word 10">
<link rel="File-List" href="fimadg_archivos/filelist.xml">
<title>______________________________</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>Fernando.Herrero</o:Author>
<o:LastAuthor>*</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>2</o:TotalTime>
<o:LastPrinted>2008-11-12T15:38:00Z</o:LastPrinted>
<o:Created>2013-03-12T12:12:00Z</o:Created>
<o:LastSaved>2013-03-12T12:12:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>45</o:Words>
<o:Characters>252</o:Characters>
<o:Lines>2</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:CharactersWithSpaces>296</o:CharactersWithSpaces>
<o:Version>10.6626</o:Version>
</o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Segoe UI";
panose-1:2 11 5 2 4 2 4 2 2 3;
mso-font-alt:Arial;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520084737 -1073683329 41 0 479 0;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:536871559 0 0 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;
text-underline:single;}
p
{mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
span.EstiloCorreo16
{mso-style-type:personal;
mso-style-noshow:yes;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Segoe UI";
mso-ascii-font-family:"Segoe UI";
mso-hansi-font-family:"Segoe UI";
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none;
text-underline:none;
text-decoration:none;
text-line-through:none;}
@page Section1
{size:595.3pt 841.9pt;
margin:70.85pt 3.0cm 70.85pt 3.0cm;
mso-header-margin:35.4pt;
mso-footer-margin:35.4pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Tabla normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]--><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/>
</o:shapelayout></xml><![endif]-->
<div class="Section1">
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Segoe UI";
mso-bidi-font-family:"Times New Roman""><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:Arial;
color:navy;mso-no-proof:yes">______________________________</span></b><span
style="font-family:"Segoe
UI";color:navy;mso-no-proof:yes"><o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><b><span
style="font-size:10.0pt; font-family:"Segoe
UI";color:navy;mso-no-proof:yes">David Gómez</span></b><span
style="font-family:Arial;mso-no-proof:yes"><o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span
style="font-size:10.0pt; font-family:"Segoe
UI";color:navy;mso-no-proof:yes">EXTERNAL </span><span
style="font-size:8.0pt;font-family:"Segoe
UI";color:navy;mso-no-proof:yes">Grupo Versia</span><span
style="font-size:10.0pt;font-family:"Segoe
UI";color:navy; mso-no-proof:yes"><br>
<br>
Telf.: 94 472 34 99 / 628 324 683 / 22017</span><span
style="font-family:Arial; mso-no-proof:yes"><o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><u><span
style="font-size:10.0pt; font-family:"Segoe
UI";color:navy;mso-no-proof:yes"><a
moz-do-not-send="true"
href="mailto:david.gomez@grupoversia.com">david.gomez@grupoversia.com</a></span></u><span
style="font-family:Arial;mso-no-proof:yes"><o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span
style="font-size:7.5pt;
font-family:Verdana;mso-bidi-font-family:Arial;color:navy;mso-no-proof:yes"><br>
</span><span style="font-size:10.0pt;font-family:"Segoe
UI";color:navy; mso-no-proof:yes">Pol. Inbisa 20B<o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span
style="font-size:10.0pt; font-family:"Segoe
UI";color:navy;mso-no-proof:yes">48510 Valle de
Trápaga</span><span
style="font-family:Arial;mso-no-proof:yes"><o:p></o:p></span></p>
<p class="MsoNormal"><u><span
style="font-size:10.0pt;font-family:"Segoe
UI"; color:navy;mso-no-proof:yes"><a
moz-do-not-send="true"
href="http://www.grupoversia.com/">www.grupoversia.com</a><o:p></o:p></span></u></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Segoe UI";
color:navy;mso-no-proof:yes"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"Segoe UI";
mso-bidi-font-family:"Times New Roman""><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Rancid-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Rancid-discuss@shrubbery.net">Rancid-discuss@shrubbery.net</a>
<a class="moz-txt-link-freetext" href="http://www.shrubbery.net/mailman/listinfo/rancid-discuss">http://www.shrubbery.net/mailman/listinfo/rancid-discuss</a></pre>
</blockquote>
<br>
</body>
</html>