Using RANCID/clogin to run commands on multiple devices

As the next step to my previous post about filtering files using egrep, I had to apply a configuration change to a number of devices on our network.

Rather than logging in manually to 1400 devices, I found that the clogin command can login to a device and run a couple of commands.

You can do it in a single line on the CLI, but I’d prefer to script things so they’re documentable and repeatable.

Here’s the script that I made, it’s fairly simple.

#!/bin/bash

for line in $(cat iplist.txt)

do

su -s /bin/bash -l rancid -c “/var/lib/rancid/bin/clogin -x command.cmds $line”

done

It reads the contents of iplist.txt, which has an IP address per line, then for each of those, it runs clogin and gives it the file for commands and the IP (specified by $line).

These are the commands (in a plain text file called command.cmds)

conf term

logging 10.0.0.5

end

write

exit

They could be anything, but I was changing the logging for a Cisco router, so that’s what I used.



#bash #Cisco #Linux #RANCID #script #Work