<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hello <var id="yui-ie-cursor"></var></div><div>I have a problem with rancid parsing script. Logs show missed cmd(s). </div><div>Trying to get all of the configs.<br>10.3.4.5: missed cmd(s): display current-configuration,display version<br>10.3.4.5: End of run not found<br>#<br>All routers sucessfully completed.</div><div>cvs diff: Diffing .<br>cvs diff: Diffing configs<br>cvs commit: Examining .<br>cvs commit: Examining configs</div><div> </div><div>The script is for Huawei. The problem now seems to be that rancid is not collecting configs.</div><div>Anyone with an idea on what to do?</div><div> </div><div>Below is the rancid-script</div><div> </div><div>#! /usr/bin/perl<br>##<br>## $Id$<br>##<br>## rancid 2.3.8<br>##<br>## Copyright (C) 1997-2004 by Terrapin Communications, Inc.<br>## All rights
reserved.<br>##<br>## This software may be freely copied, modified and redistributed<br>## without fee for non-commerical purposes provided that this license<br>## remains intact and unmodified with any RANCID distribution.<br>##<br>## There is no warranty or other guarantee of fitness of this software.<br>## It is provided solely "as is". The author(s) disclaim(s) all<br>## responsibility and liability with respect to this software's usage<br>## or its effect upon hardware, computer systems, other software, or<br>## anything else.<br>##<br>## Except where noted otherwise, rancid was written by and is maintained by<br>## Henry Kilmer, John Heasley, Andrew Partan, Pete Whiting, and Austin Schutz.<br>##<br>#<br># hurancid - Interface to Huawei devices<br>#<br># RANCID - Really Awesome New Cisco confIg Differ<br>#<br># usage: rancid [-d] [-l] [-f filename | $host]<br>#<br>use Getopt::Std;<br>getopts('dfl');<br>$log = $opt_l;<br>$debug =
$opt_d;<br>$file = $opt_f;<br>$host = $ARGV[0];<br>$clean_run = 0;<br>$found_end = 0;<br>$timeo = 90; # hulogin timeout in seconds</div><div><br>my(%filter_pwds); # password filtering mode</div><div># This routine is used to print out the router configuration<br>sub ProcessHistory {<br> my($new_hist_tag,$new_command,$command_string,@string)=(@_);</div><div>if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))<br> && defined %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} = "<a href="mailto:$history%7B$command_string%7D@string">mailto:$history%7B$command_string%7D@string</a>";<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>}</div><div><br>sub numerically { $a <=> $b;
}</div><div><br># This is a sort routing 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>}</div><div><br># This is a sort routing 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>}</div><div><br># This is a sort routing 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>}</div><div><br># This is a numerical sort routing (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>}</div><div><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>}</div><div><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>}</div><div> </div><div><br># This routine processes a "show configuration"<br># This routine processes a "show configuration"<br>sub WriteTerm {<br> print STDERR " In WriteTerm: $_" if ($debug);<br> #my($lineauto) = 0;</div><div><br> while (<INPUT>) {<br>#print STDERR "History $_\n"; <br> <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> /^/ && next;<br> ProcessHistory("COMMENTS","keysort","B1","# $_") && next;<br> }</div><div> </div><div> # end of config...is a comment.<br> if (/^return/i) {</div><div>$found_end =
1;<br> return(1);<br> }<br> <br> return(0);<br>}</div><div><br># This routine copies everything with precefing "#"<br>sub CopyComment {<br> print STDERR " In CopyComment: $_" if ($debug);</div><div><br> while (<INPUT>) {<br> tr/\015//d;<br> last if (/^$prompt/);</div><div><br> ProcessHistory("","","","# $_");<br> # end of config<br> }<br> return(0);<br>}</div><div><br># filter out "uptime" lines<br>sub FilterUptime {<br> print STDERR " In FilterUptime: $_" if
($debug);</div><div><br> while (<INPUT>) {<br> tr/\015//d;<br> last if (/^$prompt/);<br>#nmeongeza<br> next if (/^(\s*|\s*$cmd\s*)$/);<br> return(-1) if (/command authorization failed/i);</div><div> /^VERSION\=>(\s+.*)$/ &&<br>ProcessHistory("COMMENTS","keysort","C1","\#\n# Version: $1\n")<br>&& next;</div><div> /^PATCH\=>(\s+.*)$/ &&<br>ProcessHistory("COMMENTS","keysort","C2","\# Patch: $1\n")<br>&& next;</div><div><br> /^PRODUCT\=>(\s+.*)$/ &&<br>ProcessHistory("COMMENTS","keysort","C3","\# Version: $1\n")<br>&&
next;<br>}<br>return(0);<br>}</div><div> </div><div> </div><div># dummy function<br>sub DoNothing {print STDOUT;}</div><div><br># Main<br>@commandtable = (<br> {'display version' => 'FilterUptime'},<br> {'display patch-information' => 'CopyComment'},<br> {'display device' => 'CopyComment'},<br> {'display device pic-status' =>
'CopyComment'},<br> {'display current-configuration' => 'WriteTerm'},<br>);</div><div><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);</div><div><br>$huaw_cmds=join(";",@commands);<br>$cmds_regexp=join("|",@commands);</div><div><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; }</div><div><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 hulogin -t $timeo -c\"$huaw_cmds\" $host\n" if ($debug);<br> print STDOUT "executing hulogin -t $timeo -c\"$huaw_cmds\" $host\n" if ($debug);<br> if (defined($ENV{NOPIPE}) && $ENV{NOPIPE} =~ /^YES/i) {<br> system "hulogin -t $timeo -c \"$huaw_cmds\" $host </dev/null > $host.raw" || die "hulogin failed for $host: $!\n";<br> open(INPUT, "< $host.raw") || die "hulogin failed for $host: $!\n";<br> } else {<br> open(INPUT,"hulogin -t $timeo -c \"$huaw_cmds\" $host </dev/null |") || die "hulogin failed for $host: $!\n";<br> }<br>}</div><div><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>}</div><div><br>ProcessHistory("","","","#RANCID-CONTENT-TYPE: Huawei\n#\n");<br>ProcessHistory("COMMENTS","keysort","B0","#\n");<br>ProcessHistory("COMMENTS","keysort","F0","#\n");<br>ProcessHistory("COMMENTS","keysort","G0","#\n");<br>TOP: while(<INPUT>) {<br> tr/\015//d;</div><div><br>#print STDERR ("CMD: $_\n"); <br> <br> if (/\>\s?quit.*$/) {<br> $clean_run=1;<br> last;<br> }</div><div> </div><div> if (/^Error:/) {<br> print STDOUT ("$host hulogin error: $_");<br> print STDERR ("$host
hulogin error: $_") if ($debug);<br> $clean_run=0;<br> last;</div><div>}<br> <br> while (/\>\007*\s*($cmds_regexp)\s*$/) {<br> $cmd = $1;</div><div><br> if (!defined($prompt)) {<br> $prompt = ($_ =~ /^([^>]+\>)/)[0];<br> $prompt =~ s/([][}{)(<a href="file://])///$1/g">file://])///$1/g</a>;<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);</div><div> <br>if (defined($ENV{NOPIPE})) {<br> #unlink("$host.raw") if (! $debug);<br>}</div><div># 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></div><div> </div><div> </div></div></body></html>