summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorTar Committer <tar@ocjtech.us>2005-08-15 00:51:41 +0000
committerTar Committer <tar@ocjtech.us>2005-08-15 00:51:41 +0000
commitc0482931956d127b5f09d4a8d72758cd4cb1f097 (patch)
treefb13010367c3c9e3e12dc698233b729d6dd669da /bin
parent96dc4026054df77affedfe50380a661dcdba732a (diff)
downloadrancid-c0482931956d127b5f09d4a8d72758cd4cb1f097.tar.gz
rancid-c0482931956d127b5f09d4a8d72758cd4cb1f097.tar.xz
rancid-c0482931956d127b5f09d4a8d72758cd4cb1f097.zip
Imported from rancid-2.3.2a3.tar.gz.rancid-2.3.2a3
Diffstat (limited to 'bin')
-rw-r--r--bin/Makefile.in2
-rw-r--r--bin/cat5rancid.in35
-rw-r--r--bin/clogin.in74
-rw-r--r--bin/control_rancid.in57
-rw-r--r--bin/rancid-cvs.in37
-rw-r--r--bin/rancid.in49
6 files changed, 220 insertions, 34 deletions
diff --git a/bin/Makefile.in b/bin/Makefile.in
index 2bcfa3e..ec13f2d 100644
--- a/bin/Makefile.in
+++ b/bin/Makefile.in
@@ -155,6 +155,7 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
PERLV = @PERLV@
PERLV_PATH = @PERLV_PATH@
PING_PATH = @PING_PATH@
+RCSSYS = @RCSSYS@
RSH = @RSH@
SENDMAIL = @SENDMAIL@
SET_MAKE = @SET_MAKE@
@@ -162,6 +163,7 @@ SHELL = @SHELL@
SORT = @SORT@
SSH = @SSH@
STRIP = @STRIP@
+SVN = @SVN@
TAR = @TAR@
TELNET = @TELNET@
TOUCH = @TOUCH@
diff --git a/bin/cat5rancid.in b/bin/cat5rancid.in
index bea31bb..c79fc91 100644
--- a/bin/cat5rancid.in
+++ b/bin/cat5rancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: cat5rancid.in,v 1.43 2005/06/20 21:24:30 heas Exp $
+## $Id: cat5rancid.in,v 1.44 2005/08/14 01:04:07 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -666,6 +666,38 @@ sub ShowDiag {
return(0);
}
+# This routine parses "show inventory".
+sub ShowInventory {
+ print STDERR " In ShowInventory: $_" if ($debug);
+
+ while (<INPUT>) {
+ tr/\015//d;
+ return if (/^\s*\^$/);
+ last if (/^$prompt/);
+ next if (/^(\s*|\s*$cmd\s*)$/);
+ return(-1) if (/command authorization failed/i);
+ # the pager can not be disabled per-session on the PIX
+ s/^<-+ More -+>\s*//;
+
+ chomp;
+
+ # split PID/VID line
+ if (/^(NAME: ".*,) (DESCR: .*)/) {
+ ProcessHistory("INVENTORY","","", sprintf("!%-30s%s\n", $1, $2));
+ next;
+ }
+ if (/^(PID: \w?) *, (VID: .*), (SN: .*)$/) {
+ ProcessHistory("INVENTORY","","", "!$1\n!$2\n!$3\n");
+ next;
+ }
+
+ ProcessHistory("INVENTORY","","","!$_");
+ }
+ ProcessHistory("INVENTORY","","","");
+
+ return(0);
+}
+
# This routine parses "show module"
sub ShowModule {
my($slot);
@@ -1005,6 +1037,7 @@ sub DoNothing {print STDOUT;}
{'dir sup-bootflash:' => 'DirSlotN'},
{'dir sup-microcode:' => 'DirSlotN'},
{'show module' => 'ShowModule'},
+ {'show inventory raw' => 'ShowInventory'},
{'show port ifindex' => 'ShowPortIfindex'},
{'write term all' => 'WriteTerm'},
{'write term' => 'WriteTerm'},
diff --git a/bin/clogin.in b/bin/clogin.in
index d4f27db..d03feb9 100644
--- a/bin/clogin.in
+++ b/bin/clogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: clogin.in,v 1.85 2005/06/14 20:20:43 heas Exp $
+## $Id: clogin.in,v 1.89 2005/08/14 20:18:19 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -286,7 +286,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
-# returns: 0 on success, 1 on failure
+# returns: 0 on success, 1 on failure, -1 if rsh was used successfully
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
@@ -321,16 +321,79 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
return 1
}
} elseif ![string compare $prog "rsh"] {
+ global command
+
if { ! $do_command } {
+ if { [llength $cmethod] == 1 } {
+ send_user "\nError: rsh is an invalid method for -x and "
+ send_user "interactive logins\n"
+ }
if { $progs == 0 } {
return 1
}
continue;
}
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- return 1
+
+ set commands [split $command \;]
+ set num_commands [llength $commands]
+ set rshfail 0
+ for {set i 0} {$i < $num_commands && !$rshfail} { incr i} {
+ log_user 0
+ set retval [ catch {spawn rsh $user@$router [lindex $commands $i] } reason ]
+ if { $retval } {
+ send_user "\nError: rsh failed: $reason\n"
+ log_user 1; return 1
+ }
+ send_user "$router# [lindex $commands $i]\n"
+
+ # rcmd does not get a pager and no prompts, so we just have to
+ # look for failures & lines.
+ expect {
+ "Connection refused" { catch {close}; wait;
+ send_user "\nError: Connection\
+ Refused ($prog): $router\n"
+ set rshfail 1
+ }
+ -re "(Connection closed by|Connection to \[^\n\r]+ closed)" {
+ catch {close}; wait;
+ send_user "\nError: Connection\
+ closed ($prog): $router\n"
+ set rshfail 1
+ }
+ "Host is unreachable" { catch {close}; wait;
+ send_user "\nError: Host Unreachable:\
+ $router\n"
+ set rshfail 1
+ }
+ "No address associated with" {
+ catch {close}; wait;
+ send_user "\nError: Unknown host\
+ $router\n"
+ set rshfail 1
+ }
+ -re "\b+" { exp_continue }
+ -re "\[\n\r]+" { send_user -- "$expect_out(buffer)"
+ exp_continue
+ }
+ timeout { catch {close}; wait
+ send_user "\nError: TIMEOUT reached\n"
+ set rshfail 1
+ }
+ eof { catch {close}; wait }
+ }
+ log_user 1
+ }
+ if { $rshfail } {
+ if { !$progs } {
+ return 1
+ } else {
+ continue
+ }
}
+ # fake the end of the session for rancid.
+ send_user "$router# exit\n"
+ # return rsh "success"
+ return -1
} else {
send_user "\nError: unknown connection method: $prog\n"
return 1
@@ -731,6 +794,7 @@ foreach router [lrange $argv $i end] {
# Login to the router
if {[login $router $ruser $userpswd $passwd $enapasswd $cmethod $cyphertype]} {
+ # if login failed or rsh was successful, move on to the next device
continue
}
if { $enable } {
diff --git a/bin/control_rancid.in b/bin/control_rancid.in
index c33411e..98bc630 100644
--- a/bin/control_rancid.in
+++ b/bin/control_rancid.in
@@ -1,6 +1,6 @@
#! /bin/sh
##
-## $Id: control_rancid.in,v 1.69 2005/07/07 01:09:08 heas Exp $
+## $Id: control_rancid.in,v 1.71 2005/08/15 00:42:50 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -81,6 +81,13 @@ DIR=$BASEDIR/$GROUP
TMP=${TMPDIR:=/tmp}/rancid.$GROUP.$$
trap 'rm -fr $TMP;' 1 2 15
+# RCS system
+RCSSYS=${RCSSYS:=cvs};
+if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" ] ; then
+ echo "$RCSSYS is not a valid value for RCSSYS."
+ exit 1
+fi
+
# the receipient(s) of diffs & mail options
mailrcpt=${mailrcpt:-"@MAILPLUS@${GROUP}${MAILDOMAIN}"}; export mailrcpt
adminmailrcpt=${adminmailrcpt:-"@ADMINMAILPLUS@${GROUP}${MAILDOMAIN}"};
@@ -117,10 +124,10 @@ fi
# do cvs update of router.db in case anyone has fiddled.
cd $DIR
-cvs update router.db > $TMP 2>&1
+$RCSSYS update router.db > $TMP 2>&1
grep "^C" $TMP > /dev/null
if [ $? -eq 0 ] ; then
- echo "There were CVS conflicts during update."
+ echo "There were $RCSSYS conflicts during update."
echo ""
cat $TMP
rm -f $TMP
@@ -241,8 +248,12 @@ then
router=$1
touch $router
- cvs add -ko $router
- cvs commit -m 'new router' $router
+ if [ $RCSSYS = cvs ] ; then
+ cvs add -ko $router
+ else
+ svn add $router
+ fi
+ $RCSSYS commit -m 'new router' $router
echo "Added $router"
done
echo
@@ -265,23 +276,31 @@ rm -f routers.db
trap 'rm -fr $TMP;' 1 2 15
cd $DIR/configs
-# check for 'up' routers missing in cvs. no idea how this happens to some folks
+# check for 'up' routers missing in RCS. no idea how this happens to some folks
for router in `cut -d: -f1 ../routers.up` ; do
- cvs status $router | grep -i 'status: unknown' > /dev/null 2>&1
+ if [ $RCSSYS = cvs ] ; then
+ cvs status $router | grep -i 'status: unknown' > /dev/null 2>&1
+ else
+ svn status $router | grep '^?' > /dev/null 2>&1
+ fi
if [ $? -eq 0 ]; then
touch $router
- cvs add -ko $router
- echo "CVS added missing router $router"
+ if [ $RCSSYS = cvs ] ; then
+ cvs add -ko $router
+ else
+ svn add $router
+ fi
+ echo "$RCSSYS added missing router $router"
fi
done
echo
-# cvs delete configs for routers not listed in routers.up.
-for router in `find . \( -name \*.new -prune -o -name CVS -prune \) -o -type f -print | sed -e 's/^.\///'` ; do
+# delete configs from RCS for routers not listed in routers.up.
+for router in `find . \( -name \*.new -prune -o -name CVS -prune -o -name .svn -prune \) -o -type f -print | sed -e 's/^.\///'` ; do
grep -i "^$router:" ../router.db > /dev/null 2>&1
if [ $? -eq 1 ]; then
rm -f $router
- cvs delete $router
- cvs commit -m 'deleted router' $router
+ $RCSSYS delete $router
+ $RCSSYS commit -m 'deleted router' $router
echo "Deleted $router"
fi
done
@@ -291,7 +310,7 @@ cd $DIR
if [ ! -s routers.up ]
then
# commit router.db
- cvs commit -m updates router.db > /dev/null
+ $RCSSYS commit -m updates router.db > /dev/null
exit;
fi
@@ -379,8 +398,12 @@ done
# Diff the directory and then checkin.
trap 'rm -fr $TMP $TMP.diff $DIR/routers.single;' 1 2 15
cd $DIR
-cvs -f @DIFF_CMD@ | sed -e '/^RCS file: /d' -e '/^--- /d' \
+if [ $RCSSYS = "cvs" ] ; then
+ cvs -f @DIFF_CMD@ -ko | sed -e '/^RCS file: /d' -e '/^--- /d' \
-e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
+else
+ svn diff | sed -e '/^+++ /d' -e 's/^\([-+ ]\)/\1 /' >$TMP.diff
+fi
if [ $alt_mailrcpt -eq 1 ] ; then
subject="router config diffs - courtesy of $mailrcpt"
@@ -388,10 +411,10 @@ else
subject="router config diffs"
fi
if [ "X$device" != "X" ] ; then
- cvs commit -m "updates - courtesy of $mailrcpt"
+ $RCSSYS commit -m "updates - courtesy of $mailrcpt"
subject="$GROUP/$device $subject"
else
- cvs commit -m updates
+ $RCSSYS commit -m updates
subject="$GROUP $subject"
fi
diff --git a/bin/rancid-cvs.in b/bin/rancid-cvs.in
index 22d5fd2..a683f49 100644
--- a/bin/rancid-cvs.in
+++ b/bin/rancid-cvs.in
@@ -1,6 +1,6 @@
#! /bin/sh
##
-## $Id: rancid-cvs.in,v 1.16 2004/01/11 03:49:13 heas Exp $
+## $Id: rancid-cvs.in,v 1.17 2005/08/15 00:42:50 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -20,7 +20,7 @@
##
#
# Create all of the misc files & dirs needed for each group and import them
-# into CVS.
+# into CVS or Subversion.
#
# rancid-cvs
#
@@ -38,9 +38,20 @@ fi
cd $BASEDIR
+# RCS system
+RCSSYS=${RCSSYS:=cvs};
+if [ $RCSSYS != "cvs" -a $RCSSYS != "svn" ] ; then
+ echo "$RCSSYS is not a valid value for RCSSYS."
+ exit 1
+fi
+
# Top level CVS stuff
if [ ! -d $CVSROOT ]; then
- cvs init
+ if [ $RCSSYS = cvs ]; then
+ cvs -d $CVSROOT init
+ else
+ svnadmin create $CVSROOT
+ fi
fi
# Log dir
@@ -65,15 +76,21 @@ do
if [ ! -d $DIR ]; then
mkdir -p $DIR
cd $DIR
- cvs import -m "$GROUP" $GROUP new rancid
- cd $BASEDIR
- cvs co $GROUP
+ if [ $RCSSYS = cvs ]; then
+ cvs import -m "$GROUP" $GROUP new rancid
+ cd $BASEDIR
+ cvs checkout $GROUP
+ else
+ svn import -m "$GROUP" . file://$CVSROOT/$GROUP
+ cd $BASEDIR
+ svn checkout file://$CVSROOT/$GROUP $GROUP
+ fi
fi
cd $DIR
if [ ! -d configs ]; then
mkdir configs
- cvs add configs
- cvs commit -m 'new' configs
+ $RCSSYS add configs
+ $RCSSYS commit -m 'new' configs
fi
# main files
@@ -88,7 +105,7 @@ do
fi
if [ ! -f router.db ]; then
touch router.db
- cvs add router.db
- cvs commit -m 'new' router.db
+ $RCSSYS add router.db
+ $RCSSYS commit -m 'new' router.db
fi
done
diff --git a/bin/rancid.in b/bin/rancid.in
index 915be60..3183dca 100644
--- a/bin/rancid.in
+++ b/bin/rancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: rancid.in,v 1.190 2005/06/24 16:07:00 heas Exp $
+## $Id: rancid.in,v 1.193 2005/08/14 22:29:29 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -148,6 +148,7 @@ sub ShowVersion {
tr/\015//d;
if (/^$prompt/) { $found_version=1; last};
next if(/^(\s*|\s*$cmd\s*)$/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
return(0) if ($found_version); # Only do this routine once
@@ -360,6 +361,7 @@ sub ShowRedundancy {
tr/\015//d;
last if(/^$prompt/);
next if(/^(\s*|\s*$cmd\s*)$/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
# the pager can not be disabled per-session on the PIX
s/^<-+ More -+>\s*//;
@@ -384,6 +386,7 @@ sub ShowIDprom {
tr/\015//d;
last if(/^$prompt/);
next if(/^(\s*|\s*$cmd\s*)$/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
# the pager can not be disabled per-session on the PIX
s/^<-+ More -+>\s*//;
@@ -413,6 +416,7 @@ sub ShowInstallActive {
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
@@ -432,6 +436,7 @@ sub ShowEnv {
if (/^$prompt/) { $found_env=1; last};
next if (/^(\s*|\s*$cmd\s*)$/);
#return(1) if ($type !~ /^7/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
return(0) if ($found_env); # Only do this routine once
@@ -539,6 +544,7 @@ sub ShowBoot {
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
return(1) if /(Open device \S+ failed|Error opening \S+:)/;
@@ -575,6 +581,7 @@ sub ShowFlash {
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if ($type =~ /^(12[40]|7)/);
return(1) if /^\s*\^\s*$/;
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
@@ -599,6 +606,7 @@ sub DirSlotN {
next if (/^(\s*|\s*$cmd\s*)$/);
# return(1) if ($type !~ /^(12[40]|7|36)/);
return(1) if /^\s*\^\s*$/;
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /(No such device|Error Sending Request)/i;
return(1) if /\%Error: No such file or directory/;
@@ -732,6 +740,7 @@ sub ShowDiagbus {
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
#return(1) if ($type !~ /^7[05]/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
@@ -821,6 +830,7 @@ REDUX: tr/\015//d;
if (/^$prompt/) { $found_diag=1; last};
next if (/^(\s*|\s*$cmd\s*)$/);
# return(1) if ($type !~ /^(12[40]|720|36|26)/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
return(0) if ($found_diag); # Only do this routine once
@@ -1022,6 +1032,38 @@ PerlSucks:
return(0);
}
+# This routine parses "show inventory".
+sub ShowInventory {
+ print STDERR " In ShowInventory: $_" if ($debug);
+
+ while (<INPUT>) {
+ tr/\015//d;
+ return if (/^\s*\^$/);
+ last if (/^$prompt/);
+ next if (/^(\s*|\s*$cmd\s*)$/);
+ return(-1) if (/command authorization failed/i);
+ # the pager can not be disabled per-session on the PIX
+ s/^<-+ More -+>\s*//;
+
+ chomp;
+
+ # split PID/VID line
+ if (/^(NAME: ".*,) (DESCR: .*)/) {
+ ProcessHistory("INVENTORY","","", sprintf("!%-30s%s\n", $1, $2));
+ next;
+ }
+ if (/^(PID: \w?) *, (VID: .*), (SN: .*)$/) {
+ ProcessHistory("INVENTORY","","", "!$1\n!$2\n!$3\n");
+ next;
+ }
+
+ ProcessHistory("INVENTORY","","","!$_");
+ }
+ ProcessHistory("INVENTORY","","","!\n");
+
+ return(0);
+}
+
# This routine parses "show module".
sub ShowModule {
print STDERR " In ShowModule: $_" if ($debug);
@@ -1081,6 +1123,7 @@ sub ShowSpeVersion {
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
@@ -1145,6 +1188,7 @@ sub ShowVTP {
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
@@ -1170,6 +1214,7 @@ sub ShowVLAN {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
@@ -1192,6 +1237,7 @@ sub WriteTerm {
while (<INPUT>) {
tr/\015//d;
last if(/^$prompt/);
+ return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
@@ -1552,6 +1598,7 @@ sub DoNothing {print STDOUT;}
{'show module' => 'ShowModule'}, # cat 6500-ios
{'show spe version' => 'ShowSpeVersion'},
{'show c7200' => 'ShowC7200'},
+ {'show inventory raw' => 'ShowInventory'},
{'show vtp status' => 'ShowVTP'},
{'show vlan' => 'ShowVLAN'},
{'show running-config' => 'WriteTerm'},