Discussion:
[rancid] Question about custom command-file and expect
Simone Felici
2015-02-25 10:41:12 UTC
Permalink
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!

Simon
Alan McKinnon
2015-02-25 11:25:56 UTC
Permalink
On Wed, 25 Feb 2015 11:41:12 +0100
Post by Simone Felici
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.
#show ip route <IP_ADDRESS>
% Subnet not in table
I need to execute some commands.
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
Heasley
2015-02-25 12:52:48 UTC
Permalink
Post by Alan McKinnon
On Wed, 25 Feb 2015 11:41:12 +0100
Post by Simone Felici
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.
#show ip route <IP_ADDRESS>
% Subnet not in table
I need to execute some commands.
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
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?
I think he is using clogin to retrieve data. In that case he could retrieve o/p, disconnect, makes choices and connect again, using -x or -c. Or use -s. Rancid comes with some examples for -s; see the share dir.
Post by Alan McKinnon
Alan
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
Paweł Rzepa
2015-02-25 13:07:13 UTC
Permalink
Post by Alan McKinnon
On Wed, 25 Feb 2015 11:41:12 +0100
Post by Simone Felici
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.
#show ip route <IP_ADDRESS>
% Subnet not in table
I need to execute some commands.
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
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
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
Hi,

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.

Regards,
Pawel
Hughes, Doug
2015-02-25 22:01:44 UTC
Permalink
This is definitely possible, though you need to dig out your Perl coding skills. It's not that hard with a little bit of perl, but you need to be prepared to edit the rancid file corresponding to your device (e.g. crancid or jrancid or whatever)

Then it's just adding the if condition (like the "next if" already there) and perhaps calling a new subroutine, or perhaps just handling it in a { } block if it's short enough.

It's not a standard feature, though.

-----Original Message-----
From: Rancid-discuss [mailto:rancid-discuss-***@shrubbery.net] On Behalf Of Simone Felici
Sent: Wednesday, February 25, 2015 5:41 AM
To: rancid-***@shrubbery.net
Subject: [rancid] Question about custom command-file and expect


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!

Simon

Loading...