Discussion:
[rancid] Run a command in all the routers
Shekhar Basnet
2006-06-01 09:55:49 UTC
Permalink
Hello all,

Suppose I want to run a command say "show diag" in all the routers of
different router.db files, what command do I issue?

Thats one. I have 18 router.db files polling 72 devices. Now I want to
issue that command in only 9 router.db files. How do I tackle that?

TIA
S.
Chris Stave
2006-06-01 14:00:46 UTC
Permalink
I've had good luck with scripts calling clogin, my devices are sequentially
addressed, so a simple loop takes care of them all for me. It doesn't
matter so much that they're in router.db as that they are in .cloginrc. As
far as using router.db files to determine which devices get the command
issued, it's a little tougher. If it is something that you're going to use
a lot, you could write a script for each grouping. Below is my script to
connect to everything between 10.2.1.1 and 10.2.1.50 and run the commands in
cmds.txt

for (( i = 1 ; i <= 50; i++ ))
do
/home/rancid/bin/clogin -x /home/rancid/cmds.txt 10.2.1.$i
done

then you can edit cmds.txt to contain whatever commands you would like to
send, currently my cmds.txt contains:

show cdp ent *
exit


Good luck!

Chris Stave
Drew University
Post by Shekhar Basnet
Hello all,
Suppose I want to run a command say "show diag" in all the routers of
different router.db files, what command do I issue?
Thats one. I have 18 router.db files polling 72 devices. Now I want to
issue that command in only 9 router.db files. How do I tackle that?
TIA
S.
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
Dylan Vanderhoof
2006-06-01 17:44:25 UTC
Permalink
find . -name router.db |xargs cat |grep up| sed s/:.*:up//g

Running that from the rancid data-dir should give you a list of each up
device to stdout.

-D

-----Original Message-----
From: Shekhar Basnet [mailto:***@mos.com.np]
Sent: Thursday, June 01, 2006 2:56 AM
To: rancid-***@shrubbery.net
Subject: [rancid] Run a command in all the routers


Hello all,

Suppose I want to run a command say "show diag" in all the
routers of different router.db files, what command do I issue?

Thats one. I have 18 router.db files polling 72 devices. Now I
want to issue that command in only 9 router.db files. How do I tackle
that?

TIA
S.
Ed Ravin
2006-06-01 18:10:53 UTC
Permalink
Post by Dylan Vanderhoof
find . -name router.db |xargs cat |grep up| sed s/:.*:up//g
That might not work at some sites. How about this:

find . -name router.db | xargs cat | grep -w up | cut -f1 -d:

Which would avoid accidentally trying to reach routers with names
like "Frupton" that weren't in the "up" state, and be a little more
reliable parsing out the router name.

-- Ed (but all bets are off if one of your routers is named "up")
Andrew Partan
2006-06-01 18:49:12 UTC
Permalink
Post by Dylan Vanderhoof
find . -name router.db |xargs cat |grep up| sed s/:.*:up//g
Or
clogin -c "show diag" `find . -name router.db | \
xargs awk -F: '$3 == "up" && $2 == "cisco" && $1 !~ /^#/ {print $1}'`

Change cisco to the type of device you want the command to run on.

You can also do
clogin -c "show diag;show version"
if you want to run more then one command.
Or
clogin -x command_file
if command_file has a list of the commands you want to run.
Or
clogin -s script_file
if script_file is a more complex expect script.
See share/*.exp for a couple of sample expect scripts.
--asp
Jee Kay
2006-06-01 11:55:20 UTC
Permalink
Suppose I want to run a command say "show diag" in all the routers of different router.db files, what command do I issue?
Thats one. I have 18 router.db files polling 72 devices. Now I want to issue that command in only 9 router.db files. How do I tackle that?
(eww HTML email)

I don't know about the first, but for the second you can do:
./clogin -c "show diag" router1 router2 router3 router4

Ras

Loading...