script for Cisco devices

I'm a network analyst and we use Cattools to automate a lot of our configuration changes but those changes are in the masses and Cattools can be a pain in some ways, especially if all I want to change is three or four devices. I've done a few small simple bash scripts in my time but I can't seem to find a way to get a bash script to read a file with a list of IP addresses, SSH into them with a username and password, send the configuration commands, write the changes, exit, then go on to the next device. I know how to do a read line but I'm not sure how to get the IP into a variable and then carry out further. I know someone who is a script kitty could push this out in a matter of minutes. Any help would be greatly appreciated. Just need something I can build off of and learn from. Below is my idea of how it would work. The username and password will always be the same as I implemented TACACS+ in our environment.

Code:
username=bob
password=myPassword
file=ipList.txt
command1="command to push"
command2="command to push"

while read line from $file
do "ssh into first line IP"
 put in username password
  push config command1
  push config command2
    save config
    exit
done
 
To use SSH in a script you would have to use keys for authentication or else the script is going to stop to ask for the password each time it logs in on a device.

I would use Perl and the net/p5-Net-SSH-Perl module to script everything. The module allows you to connect with a password making it easier to automate. Perl will also make it easier to fetch the config, process it and add commands if they're missing or incorrect.
 
Thanks for the advice @SirDice. However, I don't know any Perl. I know a little bit of Python. I will look into see what I can do with Perl. I have a friend who knows Perl. Thanks again.
 
Last edited by a moderator:
If you know Python there are probably similar modules for it. I don't know Python but I do know Perl :e
 
Back
Top