[rancid] Re: Newbie Question...sorry!

Mike Ashcraft mashcraft at omniture.com
Mon Oct 15 23:52:27 UTC 2007

As John H already mentioned, xargs(1)  is your friend here.  
Start with a text file listing your devices, one per line.  If you don't
have this already try cut(1) on your router.db file.
I'll provide a few examples.
Run the commands in cmds.txt on the devices listed in devices.txt:
cat devices.txt | xargs clogin -x cmds.txt
If the commands need to include the device name as James requested,
create a custom script that runs the right command when passed the
devicename.  Then pass this script the devices in the list one at a
cat devices.txt | xargs -n1 customscript.sh

From: rancid-discuss-bounces at shrubbery.net
[mailto:rancid-discuss-bounces at shrubbery.net] On Behalf Of Chris Stave
Sent: Monday, October 15, 2007 9:58 AM
To: Munroe, James (DSS/MAS)
Cc: rancid-discuss at shrubbery.net
Subject: [rancid] Re: Newbie Question...sorry!

I've made a script to call clogin, our devices are numbered fairly
sequentially, from <>  to
<>  with cluster members getting 10.0.1.x and 10.0.2.x
, etc... 
I put whatever commands I want to run into cmds.txt and then make sure
that the switches I want those commands run on are represented in the
script.  A slight change to this would be to put the actual command you
want to run in in place of the cmds.txt, which would make it easy to
specify the ip address as a filename for the log.

This obviously works better if your devices are all similarly numbered.

I've appended the script, but do note that it won't work for you without
changes, but just as an example of how I did it.  I suspect that there
is a cleaner way to do the conditional statements, but this way worked
for me. (As a bonus, is there an easy way to avoid the repeated "-o $i
=" in the script below?) 

for ((  i = 1;  i <= 86;  i++  ))
 /home/rancid/bin/clogin -x /home/rancid/cmds.txt 10.0.0.$i 
if [ $i = 6 -o $i = 12 -o $i = 13 -o $i = 14 -o $i = 16 -o $i = 19 -o $i
= 23 -o 
 $i = 27 -o $i = 30 -o $i = 32 -o $i = 37 -o $i = 44 -o $i = 45 -o $i =
46 -o $i
 = 48 -o $i = 49 -o $i = 52 -o $i = 53 -o $i = 55 -o $i = 56 -o $i = 57
-o $i =
58 -o $i = 59 -o $i = 60 -o $i = 61 -o $i = 64 -o $i = 65 -o $i = 70 -o
$i = 71 
-o $i = 81 -o $i = 72 -o $i = 73 -o $i = 77 -o $i = 82 -o $i = 83 -o $i
= 84 -o
$i = 85 -o $i = 86 ]; then
 /home/rancid/bin/clogin -x /home/rancid/cmds.txt 10.0.1.$i
if [ $i = 6 -o $i = 12 -o $i = 14 -o $i = 23 -o $i = 37 -o $i = 44 -o $i
= 45 -o 
 $i = 52 -o $i = 53 -o $i = 57 -o $i = 61 -o $i = 64 -o $i = 72 -o $i =
73 -o $i
 = 77 -o $i = 83 -o $i = 86 ]; then
 /home/rancid/bin/clogin -x /home/rancid/cmds.txt 10.0.2.$i
if [ $i = 6 -o $i = 12 -o $i = 37 -o $i = 53 -o $i = 57 -o $i = 61 -o
$i=64 ]; t 
 /home/rancid/bin/clogin -x /home/rancid/cmds.txt 10.0.3.$i


good luck with it! 

On 10/15/07, Munroe, James (DSS/MAS) <James.Munroe at gnb.ca> wrote: 

	Could someone please tell me if there is a way to add a variable
to a command file for processing with nlogin?  For example I want to
issue the following command on 170 simliar devices:  "get event > tftp <ROUTERNAME>.log"  The <ROUTERNAME> needs to be unique for
each device.  I don't care if it's the device's IP or hostname or
whatever...as long as it is unique.  Hostname or IP would be nice though
	Also when using nlogin or clogin what's the easiest way to
specify a large number of remote devices?  I've got like 380+ firewalls
and routers that I'd like to issue a nlogin/clogin against.  I know the
command line gives you the option to list each deviceon the same command
line...but I was looking for something a little more manageable.  I'd
eventually like to automate this...or script it. 
	Any help or tips would be greatly appreciated!!!
	Rancid-discuss mailing list
	Rancid-discuss at shrubbery.net 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20071015/28fb6a6e/attachment.html 

More information about the Rancid-discuss mailing list