[rancid] Question about custom command-file and expect

Paweł Rzepa pawel.rzepa at gmail.com
Wed Feb 25 13:07:13 UTC 2015

W dniu 25.02.2015 o 12:25, Alan McKinnon pisze:
> On Wed, 25 Feb 2015 11:41:12 +0100
> Simone Felici <s.felici at mclink.eu> wrote:
>> Hello,
>> I would like to connect on a device using rancid and execute some
>> commands *only* in some circumstances. clogin works perfectly to
>> login and using -x to specify a command-list file or -c to execute
>> commands works as well. But what I need is that, based on the
>> response of a command I could execute another command or not.
>> I.e., after login on a router, executing:
>> #show ip route <IP_ADDRESS>
>> IF I obtain:
>> % Subnet not in table
>> I need to execute some commands.
>> If I obtain:
>> Routing entry for <IP_ADDRESS>
>> (...)
>> THEN I need to do something different.
>> I've seen there is a [-s script-file] where I could add an expect
>> script. Trying to use it, seems the whole content of clogin is
>> bypassed using the script file. Would be possible to use clogin for
>> login action and then, at the end, use only the script-file to add
>> the rest of the commands with the IF-THEN-ELSE logic?
>> Thanks for the help!
> I think you are trying to solve a problem that does not exist. Rancid
> won't run a command like this:
> show ip route <IP_ADDRESS>
> Instead, it will show all the routes, grab all of them, sort all of
> them and put the whole lot into cvs. Running specific commands like you
> suggest breaks the rancid model, which is to track everything in a
> repeatable way so that the only differences are configurations.
> I can't think of a circumstance where you would want to do what you
> describe. If that was just an example for illustration, perhaps you
> could describe the real problem?
> Alan
> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at shrubbery.net
> http://www.shrubbery.net/mailman/listinfo/rancid-discuss

What about running rancid twice?
First you run rancid with 'show-ip-route-or-anything-else', then parse 
the output with whatever you want (perl/bash/etc) and depending on the 
result run rancid for the second time with your new commands?
Maybe it against the idea of rancid, requires to connect to the remote 
device twice so it is not as fast as for the single run, but is quick to 
implement and does its job.


More information about the Rancid-discuss mailing list