diff -urNa rancid-2.3.2/bin/clogin.in rancid-2.3.2-new/bin/clogin.in --- rancid-2.3.2/bin/clogin.in 2009-10-20 10:26:53.000000000 +0200 +++ rancid-2.3.2-new/bin/clogin.in 2009-10-20 10:27:49.000000000 +0200 @@ -607,7 +607,7 @@ } # match cisco config mode prompts too, such as router(config-if)#, # but catalyst does not change in this fashion. - regsub -all {^(.{1,11}).*([#>])$} $prompt {\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt + regsub -all {^([^\/]+).*([#>])$} $prompt {\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt expect { -re $reprompt {} -re "\[\n\r]+" { exp_continue } diff -urNa rancid-2.3.2/bin/cssrancid.in rancid-2.3.2-new/bin/cssrancid.in --- rancid-2.3.2/bin/cssrancid.in 2009-10-20 10:26:53.000000000 +0200 +++ rancid-2.3.2-new/bin/cssrancid.in 2009-10-20 11:49:39.000000000 +0200 @@ -45,7 +45,7 @@ # usage: rancid [-dV] [-l] [-f filename | hostname] # use Getopt::Std; -getopts('dflV'); +getopts('c:dflV'); if ($opt_V) { print "rancid 2.3.2\n"; exit(0); @@ -53,16 +53,20 @@ $log = $opt_l; $debug = $opt_d; $file = $opt_f; +@contexts = split(",", $opt_c); $host = $ARGV[0]; $clean_run = 0; $found_end = 0; $timeo = 90; # clogin timeout in seconds +$changeto_called = 0; my(@commandtable, %commands, @commands);# command lists my($aclsort) = ("ipsort"); # ACL sorting mode my($filter_commstr); # SNMP community string filtering my($filter_pwds); # password filtering mode +my $contextstring = "[" . join(",",@contexts) . "]" if ($#contexts >= 0); + # This routine is used to print out the router configuration sub ProcessHistory { my($new_hist_tag,$new_command,$command_string,@string) = (@_); @@ -277,6 +281,14 @@ } +# Dummy routine to set context.... +sub ChangeTo { + print STDERR " In ChangeTo: $_" if ($debug); + $changeto_called = 1; + $_ = ; + return(0); +} + # Dummy routine to set term length.... sub TermLength { # Dummy subroutine.. need to set term length differently for CSS @@ -583,6 +595,13 @@ {'show boot' => 'ShowBoot'}, {'show run' => 'ShowRun'} ); + + +my $spacecount=1; # We need to different the commands from eachother, +#else they will be deleted from the genereated array when the first one of the commands are being run. +#easiest way is incrementing the number of spaces between show and running. +push (@commandtable, map { ( {"changeto $_" => 'ChangeTo'} , {"show". " "x $spacecount++ ."running" => 'ShowRun'} ) } @contexts); + # Use an array to preserve the order of the commands and a hash for mapping # commands to the subroutine and track commands that have been completed. @commands = map(keys(%$_), @commandtable); @@ -591,6 +610,7 @@ $cisco_cmds = join(";",@commands); $cmds_regexp = join("|",@commands); + if (length($host) == 0) { if ($file) { print(STDERR "Too few arguments: file name required\n"); @@ -600,21 +620,21 @@ exit(1); } } -open(OUTPUT,">$host.new") || die "Can't open $host.new for writing: $!\n"; +open(OUTPUT,">${host}${contextstring}.new") || die "Can't open ${host}${contextstring}.new for writing: $!\n"; select(OUTPUT); # make OUTPUT unbuffered if debugging if ($debug) { $| = 1; } if ($file) { - print STDERR "opening file $host\n" if ($debug); - print STDOUT "opening file $host\n" if ($log); - open(INPUT,"<$host") || die "open failed for $host: $!\n"; + print STDERR "opening file ${host}${contextstring}\n" if ($debug); + print STDOUT "opening file ${host}${contextstring}\n" if ($log); + open(INPUT,"<${host}${contextstring}") || die "open failed for ${host}${contextstring}: $!\n"; } else { print STDERR "executing clogin -t $timeo -c\"$cisco_cmds\" $host\n" if ($debug); print STDOUT "executing clogin -t $timeo -c\"$cisco_cmds\" $host\n" if ($log); if (defined($ENV{NOPIPE})) { - system "clogin -t $timeo -c \"$cisco_cmds\" $host $host.raw 2>&1" || die "clogin failed for $host: $!\n"; - open(INPUT, "< $host.raw") || die "clogin failed for $host: $!\n"; + system "clogin -t $timeo -c \"$cisco_cmds\" $host ${host}${contextstring}.raw 2>&1" || die "clogin failed for $host: $!\n"; + open(INPUT, "< ${host}${contextstring}.raw") || die "clogin failed for $host: $!\n"; } else { open(INPUT,"clogin -t $timeo -c \"$cisco_cmds\" $host ) { NEXT: tr/\015//d; @@ -660,9 +679,10 @@ } if (/#\s*($cmds_regexp)\s*$/) { $cmd = $1; - if (!defined($prompt)) { + if (!defined($prompt) || $changeto_called) { $prompt = ($_ =~ /^([^#]+#)/)[0]; $prompt =~ s/([][}{)(\\])/\\$1/g; + $changeto_called = 0; print STDERR ("PROMPT MATCH: $prompt\n") if ($debug); } print STDERR ("HIT COMMAND:$_") if ($debug); @@ -689,7 +709,7 @@ close(OUTPUT); if (defined($ENV{NOPIPE})) { - unlink("$host.raw") if (! $debug); + unlink("${host}${contextstring}.raw") if (! $debug); } # check for completeness @@ -701,7 +721,7 @@ if (!$clean_run || !$found_end) { print STDOUT "$host: End of run not found\n"; print STDERR "$host: End of run not found\n" if ($debug); - system("/usr/bin/tail -1 $host.new"); + system("/usr/bin/tail -1 ${host}${contextstring}.new"); } - unlink "$host.new" if (! $debug); + unlink "${host}${contextstring}.new" if (! $debug); } diff -urNa rancid-2.3.2/bin/rancid-fe.in rancid-2.3.2-new/bin/rancid-fe.in --- rancid-2.3.2/bin/rancid-fe.in 2009-10-20 10:26:53.000000000 +0200 +++ rancid-2.3.2-new/bin/rancid-fe.in 2009-10-20 11:52:38.000000000 +0200 @@ -47,10 +47,18 @@ require 5; -($router, $vendor) = split('\:', $ARGV[0]); +my ($router, $vendor) = split('\:', $ARGV[0]); +my ($contextstring); $vendor =~ tr/[A-Z]/[a-z]/; -%vendortable = ( +if ($router =~ m/([^[]+)\[([^]]+)\]/) { + +$router = $1; +$contextstring = " -c " . $2; + +} + +my %vendortable = ( 'agm' => 'agmrancid', 'alteon' => 'arancid', 'avocent' => 'avorancid', @@ -87,7 +95,7 @@ printf(STDERR "unknown router manufacturer for $router: $vendor\n"); exit(-1); } else { - exec($vendortable{$vendor} . " $router"); + exec($vendortable{$vendor} . "$contextstring $router"); } printf(STDERR "exec failed router manufacturer $vendor: $!\n");