Mon, Feb 18, 2019 at 06:20:20PM +0000, Anderson, Charles R:
> I'd like to add some custom Junos commands in rancid.types.conf such as:
>
> wpi-juniper;command;junos::ShowChassisHardware;show lldp neighbors | match
> "^Local | ae[0-9]+ "
> wpi-juniper;command;junos::ShowChassisHardware;show system commit | except
> ^rescue | trim 4 | except "by apipush via"
>
> These are rather WPI-specific, filtering output based on local conventions,
> so they are not suitable for distribution with upstream
> RANCID (although the "show system commit | except ^rescue | trim 4" part
> could be worthy of upstream inclusion--it shows the commit messages people
> gave when they changed the config--but the rollback numbers rotate and need
> to be trimmed out, hence the "| trim 4" part). By doing filtering in the
> Junos CLI, it allows local customizations without the need to write a new
> RANCID module to filter the output. This works fine except for the " double
> quote characters, which mess up when passed to system() and open() calls.
> The attached patch escapes these double quotes before passing the command to
> the system() or open(). The \" escaping cannot be done in rancid.types.conf
> because it will cause problems with the command name not matching the CLI
> output.
Seems reasonable to me. Thanks for the patch!
> --- rancid.orig 2019-02-06 02:03:28.000000000 -0500
> +++ rancid 2019-02-13 13:32:04.103689467 -0500
> @@ -116,12 +116,14 @@
> print(STDERR "opening file $host\n") if ($debug || $log);
> open(INPUT,"<$host") || die "open failed for $host: $!\n";
> } else {
> - print(STDERR "executing $lscript -t $timeo -c\"$commandstr\" $host\n")
> if ($debug || $log);
> + my $cstr = $commandstr;
> + $cstr =~ s/\"/\\\"/g;
> + print(STDERR "executing $lscript -t $timeo -c\"$cstr\" $host\n") if
> ($debug || $log);
> if (defined($ENV{NOPIPE}) && $ENV{NOPIPE} =~ /^YES/i) {
> - system "$lscript -t $timeo -c \"$commandstr\" $host </dev/null >
> $host.raw 2>&1" || die "clogin failed for $host: $!\n";
> + system "$lscript -t $timeo -c \"$cstr\" $host </dev/null > $host.raw
> 2>&1" || die "clogin failed for $host: $!\n";
> open(INPUT, "< $host.raw") || die "clogin failed for $host: $!\n";
> } else {
> - open(INPUT,"$lscript -t $timeo -c \"$commandstr\" $host </dev/null |")
> || die "clogin failed for $host: $!\n";
> + open(INPUT,"$lscript -t $timeo -c \"$cstr\" $host </dev/null |") || die
> "clogin failed for $host: $!\n";
> }
> }
>
> _______________________________________________
> Rancid-discuss mailing list
> [email protected]
> http://www.shrubbery.net/mailman/listinfo/rancid-discuss
_______________________________________________
Rancid-discuss mailing list
[email protected]
http://www.shrubbery.net/mailman/listinfo/rancid-discuss