Does any one know how to write a batch file to configure cisco switches.
for example i have 20 2970 switches, and i dont want to enter each one by one to change the password.
the lines are simple:
line vty 0 15
does anyone know how to include this in a batch file, so that i can telnet each switch and run these commands. ?
its more of a sample to do whatever you want.
expect works like a chat script, you do something and then you evaluate what you got back. You can use it to do whatever commands you want, you just have to add some more line to the script. The basis of the script I sent was to give you an idea of what you can do. Every command on the router gives you something and then returns you to the prompt, on the router in enable mode, the prompt ends with a #. So the # is what I set the expect script to expect back. Basically your saying, do a command and wait till you see a # on a line, that means your done with that command and you can now enter another command.
I used variables in the script so that you can use the script on devices with different passwords without having to rewrite the script every time. Again, just to give you an idea of how it works.
If you had a file of ips, it would be a plain text file, one ip per line, like this:
nothing fancy, just text.
The script I attached just changes the vty password, but if you want to change the enable password, just follow the script to somepoint where you'd be in global config mode (the mode your in after you type "config t" ) and then add a few lines that change the enable password. expect is very flexible and pretty easy to learn. Just for your reference, expect is based on TCL so if you want to add loops or an if statement, google "tcl if" or get a tcl book.
the attached file would be run from a box that had expect installed (either *nix or windows) and you would call it with something like this:
expect telnet.expect 10.1.1.1 pass enablepass newpass
If you had a text file with all the switch ip addresses then you could write a script to do all your changes. Assuming your file with the ip's is called switches.txt:
for i in $(cat switches.txt); do expect telnet.expect $i pass enablepass newpass ; done