Mailing List Archive

cssrancid script issues(correction of script output)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

My output parser screwed up output.... down below is the correct output for
the correct device.

cssrancid -d l-cust-msn-1.msn-cust.com
executing clogin -t 90 -c"term length 65535;copy profile user-profile;show
version;show boot;show running-config" l-cust-msn-1.msn-cust.com
HIT COMMAND:l-cust-msn-1# term length 65535
HIT COMMAND:l-cust-msn-1# term length 65535
l-cust-msn-1.msn-cust.com: found unexpected command - "term length 65535"
HIT COMMAND:l-cust-msn-1# copy profile user-profile
HIT COMMAND:l-cust-msn-1# copy profile user-profile
l-cust-msn-1.msn-cust.com: found unexpected command - "copy profile
user-profile"
HIT COMMAND:l-cust-msn-1# show version
In ShowVersion: l-cust-msn-1# show version
HIT COMMAND:l-cust-msn-1# show running-config
In ShowRun: l-cust-msn-1# show running-config
l-cust-msn-1.msn-cust.com: missed cmd(s): show boot
l-cust-msn-1.msn-cust.com: missed cmd(s): show boot
l-cust-msn-1.msn-cust.com: End of run not found
l-cust-msn-1.msn-cust.com: End of run not


- --

- --------------------------------------------------
Jeremy M. Guthrie jeremy.guthrie at berbee.com
Senior Network Engineer Phone: 608-298-1061
Berbee Fax: 608-288-3007
5520 Research Park Drive NOC: 608-298-1102
Madison, WI 53711
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBCGpMqtjaBHGZBeURAslmAJ9IT/T6pg0RhIUE31NYPKTFzkN9cQCdHNUc
6Hd7lUfXhffwL+6EoLhywug=
=heAs
-----END PGP SIGNATURE-----
cssrancid script issues(correction of script output) [ In reply to ]
Please try the attached patch.
-------------- next part --------------
Index: cssrancid.in
===================================================================
RCS file: /home/rancid/.CVS/rancid/bin/cssrancid.in,v
retrieving revision 1.4
diff -u -r1.4 cssrancid.in
--- cssrancid.in 11 Jan 2004 03:49:13 -0000 1.4
+++ cssrancid.in 29 Jul 2004 18:57:01 -0000
@@ -141,7 +141,6 @@

while (<INPUT>) {
tr/\015//d;
- study;
last if(/^$prompt/);
next if(/^(\s*|\s*$cmd\s*)$/);
return(-1) if (/command authorization failed/i);
@@ -254,6 +253,8 @@
sub TermLength {
# Dummy subroutine.. need to set term length differently for CSS
# boxes as term length 0 doesnt work correctly. POS.
+ print STDERR " In TermLength: $_" if ($debug);
+ $_ = <INPUT>;
return(0);
}

@@ -264,6 +265,8 @@
## of couse breaks the interaction... strangely enough tho
## in a failover environment, only the secondary behaves this
## way.. the primary lets you log out and does not complain.
+ print STDERR " In CopyProfile: $_" if ($debug);
+ $_ = <INPUT>;
return(0);
}

@@ -283,6 +286,7 @@
return(1) if /Ambiguous command/i;
# return(1) if /(Invalid input detected|Type help or )/;
return(1) if /(Open device \S+ failed|Error opening \S+:)/;
+ next if (/\*\* BOOT CONFIG /);
next if /CONFGEN variable/;
if (!defined($H0)) {
$H0=1; ProcessHistory("COMMENTS","keysort","H0","!\n");
@@ -305,17 +309,18 @@
# This routine processes a "show run"
sub ShowRun {
print STDERR " In ShowRun: $_" if ($debug);
- my($lineauto) = 0;
+ my($lines) = 0;

while (<INPUT>) {
tr/\015//d;
- study;
- last if(/^$prompt/);
+ if(/^$prompt/) {
+ $found_end = 1 if ($lines > 4);
+ return(1);
+ }
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
s/^<-+ More -+>\s*//;
/Non-Volatile memory is in use/ && return(-1); # NvRAM is locked
- $lineauto = 0 if (/^[^ ]/);
# skip the crap
if (/^(##+$|(Building|Current) configuration)/i) {
while (<INPUT>) {
@@ -335,13 +340,13 @@
/^! (Last configuration|NVRAM config last)/ && next;
## CSS specific....
/Generated on/ && next;
+ $lines++;

# Dog gone Cool matches to process the rest of the config
/^tftp-server flash / && next; # kill any tftp remains
/^ntp clock-period / && next; # kill ntp clock-period
/^ length / && next; # kill length on serial lines
/^ width / && next; # kill width on serial lines
- $lineauto = 1 if /^ modem auto/;
/^ speed / && $lineauto && next; # kill speed on serial lines
/^ clockrate / && next; # kill clockrate on serial interfaces
if (/^(enable )?(password|passwd) / && $filter_pwds >= 1) {
@@ -360,11 +365,9 @@
}
next;
}
- if (/^username (\S+)(\s.*)? password ((\d) \S+|\S+)/) {
- if ($filter_pwds == 2) {
- ProcessHistory("USER","keysort","$1","!username $1$2 password <removed>\n");
- } elsif ($filter_pwds == 1 && $4 ne "5"){
- ProcessHistory("USER","keysort","$1","!username $1$2 password <removed>\n");
+ if (/\s*username (\S+)(\s.*)? (des-password|password) (\S+|\S+)/) {
+ if ($filter_pwds >= 1) {
+ ProcessHistory("USER","keysort","$1","! username $1$2 $3 <removed>$'\n");
} else {
ProcessHistory("USER","keysort","$1","$_");
}
@@ -537,11 +540,6 @@

# catch anything that wasnt matched above.
ProcessHistory("","","","$_");
- # end of config. the ": " game is for the PIX
- if (/^(: +)?end$/ || /CSS.*#/ || /$prompt/ ) {
- $found_end = 1;
- return(1);
- }
}
return(0);
}
@@ -599,12 +597,13 @@
}

ProcessHistory("","","","!RANCID-CONTENT-TYPE: cisco-css\n!\n");
-ProcessHistory("COMMENTS","keysort","B0","!\n");
-ProcessHistory("COMMENTS","keysort","F0","!\n");
-ProcessHistory("COMMENTS","keysort","G0","!\n");
+#ProcessHistory("COMMENTS","keysort","B0","!\n");
+#ProcessHistory("COMMENTS","keysort","F0","!\n");
+#ProcessHistory("COMMENTS","keysort","G0","!\n");

TOP: while(<INPUT>) {
- tr/\015//d;
+NEXT:
+ tr/\015//d;
if (/\#\s?exit/) {
$clean_run=1;
last;
@@ -615,23 +614,27 @@
$clean_run=0;
last;
}
- while (/#\s*($cmds_regexp)\s*$/) {
+ if (/#\s*($cmds_regexp)\s*$/) {
$cmd = $1;
- if (!defined($prompt)) {$prompt = ($_ =~ /^([^#]+#)/)[0]; }
+ if (!defined($prompt)) {
+ $prompt = ($_ =~ /^([^#]+#)/)[0];
+ $prompt =~ s/([][}{)(\\])/\\$1/g;
+ print STDERR ("PROMPT MATCH: $prompt\n") if ($debug);
+ }
print STDERR ("HIT COMMAND:$_") if ($debug);
if (! defined($commands{$cmd})) {
print STDERR "$host: found unexpected command - \"$cmd\"\n";
- # $clean_run = 0;
- # last TOP;
- next TOP;
- } else {
- $rval = &{$commands{$cmd}};
- delete($commands{$cmd});
- if ($rval == -1) {
- $clean_run = 0;
- last TOP;
- }
+ $clean_run = 0;
+ last TOP;
+ }
+ $rval = &{$commands{$cmd}};
+ delete($commands{$cmd});
+ if ($rval == -1) {
+ $clean_run = 0;
+ last TOP;
}
+ # the function may have read the next prompt/cmd line
+ goto NEXT;
}
}
print STDOUT "Done $logincmd: $_\n" if ($log);
cssrancid script issues(correction of script output) [ In reply to ]
Thanks for the quick response. 8) I will give this a try tomorrow and let you know!


-----Original Message-----
From: john heasley [mailto:heas@shrubbery.net]
Sent: Thu 7/29/2004 2:02 PM
To: Guthrie, Jeremy
Cc: rancid-discuss at shrubbery.net
Subject: Re: cssrancid script issues(correction of script output)

Please try the attached patch.
cssrancid script issues(correction of script output) [ In reply to ]
didn't work.

Here is what I ran to debug:
cssrancid -d l-cust-msn-1 > & l-cust-msn-1.log ; clogin -t 90 -c"term length 65535;copy profile user-profile;show version;show boot;show run" l-cust-msn-1 >> & l-cust-msn-1.log

Attached is the output.


-----Original Message-----
From: john heasley [mailto:heas@shrubbery.net]
Sent: Thu 7/29/2004 2:02 PM
To: Guthrie, Jeremy
Cc: rancid-discuss at shrubbery.net
Subject: Re: cssrancid script issues(correction of script output)

Please try the attached patch.




-------------- next part --------------
A non-text attachment was scrubbed...
Name: l-cust-msn-1.log
Type: application/octet-stream
Size: 3615 bytes
Desc: l-cust-msn-1.log
Url : http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20040729/10c1a7a0/attachment.obj