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.
for line in $(cat iplist.txt)
su -s /bin/bash -l rancid -c “/var/lib/rancid/bin/clogin -x command.cmds $line”
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)
They could be anything, but I was changing the logging for a Cisco router, so that’s what I used.