So after an hour of research and experimentation, I found a way to generate 100 ip route commands without any problem. I tried it on loopback interfaces configuration and it worked fine! Check the script below.
foreach number {
1
2
3
4
5
6
} { puts [ ios_config "interface Loopback$number" ] }
It's almost the same as the common TCL ping script I use but the keyword "ios_config" made the difference. This keyword makes you execute any global configuration command in TCL. For example's sake I used only 6 numbers. I will post later the 100 loopbacks I created.
Now what the heck is a loopback without any ip address. Useless isn't it? I also found a way to map an ip address to a loopback in TCL. You use multiple variables.
foreach {number address} {
1 3.3.4.1
2 3.3.4.2
3 3.3.4.3
4 3.3.4.4
5 3.3.4.5
6 3.3.4.6
} { puts [ ios_config "interface Loopback$number" "ip address $address 255.255.255.255" ] }
Now, if you notice after the "interface Loopack$number" there is a subcommand for interface configuration mode. You can add as many commands as you want like descriptions. Just enclose it with parenthesis.
Just be creative with your script. I also used it to announce 500 prefixes in BGP just for fun. As promised here is my "show ip interface brief" showing the loopbacks.
Router#sh ip int br
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset administratively down down
Loopback1 3.3.4.1 YES unset up up
Loopback2 3.3.4.2 YES unset up up
Loopback3 3.3.4.3 YES unset up up
Loopback4 3.3.4.4 YES unset up up
Loopback5 3.3.4.5 YES unset up up
Loopback6 3.3.4.6 YES unset up up
Loopback7 3.3.4.7 YES unset up up
Loopback8 3.3.4.8 YES unset up up
Loopback9 3.3.4.9 YES unset up up
Loopback10 3.3.4.10 YES unset up up
Loopback11 3.3.4.11 YES unset up up
Loopback12 3.3.4.12 YES unset up up
Loopback13 3.3.4.13 YES unset up up
Loopback14 3.3.4.14 YES unset up up
Loopback15 3.3.4.15 YES unset up up
Loopback16 3.3.4.16 YES unset up up
Loopback17 3.3.4.17 YES unset up up
Loopback18 3.3.4.18 YES unset up up
Loopback19 3.3.4.19 YES unset up up
Loopback20 3.3.4.20 YES unset up up
Loopback21 3.3.4.21 YES unset up up
Loopback22 3.3.4.22 YES unset up up
Loopback23 3.3.4.23 YES unset up up
Loopback24 3.3.4.24 YES unset up up
Loopback25 3.3.4.25 YES unset up up
Loopback26 3.3.4.26 YES unset up up
Loopback27 3.3.4.27 YES unset up up
Loopback28 3.3.4.28 YES unset up up
Loopback29 3.3.4.29 YES unset up up
Loopback30 3.3.4.30 YES unset up up
Loopback31 3.3.4.31 YES unset up up
Loopback32 3.3.4.32 YES unset up up
Loopback33 3.3.4.33 YES unset up up
Loopback34 3.3.4.34 YES unset up up
Loopback35 3.3.4.35 YES unset up up
Loopback36 3.3.4.36 YES unset up up
Loopback37 3.3.4.37 YES unset up up
Loopback38 3.3.4.38 YES unset up up
Loopback39 3.3.4.39 YES unset up up
Loopback40 3.3.4.40 YES unset up up
Loopback41 3.3.4.41 YES unset up up
Loopback42 3.3.4.42 YES unset up up
Loopback43 3.3.4.43 YES unset up up
Loopback44 3.3.4.44 YES unset up up
Loopback45 3.3.4.45 YES unset up up
Loopback46 3.3.4.46 YES unset up up
Loopback47 3.3.4.47 YES unset up up
Loopback48 3.3.4.48 YES unset up up
Loopback49 3.3.4.49 YES unset up up
Loopback50 3.3.4.50 YES unset up up
Loopback51 3.3.4.51 YES unset up up
Loopback52 3.3.4.52 YES unset up up
Loopback53 3.3.4.53 YES unset up up
Loopback54 3.3.4.54 YES unset up up
Loopback55 3.3.4.55 YES unset up up
Loopback56 3.3.4.56 YES unset up up
Loopback57 3.3.4.57 YES unset up up
Loopback58 3.3.4.58 YES unset up up
Loopback59 3.3.4.59 YES unset up up
Loopback60 3.3.4.60 YES unset up up
Loopback61 3.3.4.61 YES unset up up
Loopback62 3.3.4.62 YES unset up up
Loopback63 3.3.4.63 YES unset up up
Loopback64 3.3.4.64 YES unset up up
Loopback65 3.3.4.65 YES unset up up
Loopback66 3.3.4.66 YES unset up up
Loopback67 3.3.4.67 YES unset up up
Loopback68 3.3.4.68 YES unset up up
Loopback69 3.3.4.69 YES unset up up
Loopback70 3.3.4.70 YES unset up up
Loopback71 3.3.4.71 YES unset up up
Loopback72 3.3.4.72 YES unset up up
Loopback73 3.3.4.73 YES unset up up
Loopback74 3.3.4.74 YES unset up up
Loopback75 3.3.4.75 YES unset up up
Loopback76 3.3.4.76 YES unset up up
Loopback77 3.3.4.77 YES unset up up
Loopback78 3.3.4.78 YES unset up up
Loopback79 3.3.4.79 YES unset up up
Loopback80 3.3.4.80 YES unset up up
Loopback81 3.3.4.81 YES unset up up
Loopback82 3.3.4.82 YES unset up up
Loopback83 3.3.4.83 YES unset up up
Loopback84 3.3.4.84 YES unset up up
Loopback85 3.3.4.85 YES unset up up
Loopback86 3.3.4.86 YES unset up up
Loopback87 3.3.4.87 YES unset up up
Loopback88 3.3.4.88 YES unset up up
Loopback89 3.3.4.89 YES unset up up
Loopback90 3.3.4.90 YES unset up up
Loopback91 3.3.4.91 YES unset up up
Loopback92 3.3.4.92 YES unset up up
Loopback93 3.3.4.93 YES unset up up
Loopback94 3.3.4.94 YES unset up up
Loopback95 3.3.4.95 YES unset up up
Loopback96 3.3.4.96 YES unset up up
Loopback97 3.3.4.97 YES unset up up
Loopback98 3.3.4.98 YES unset up up
Loopback99 3.3.4.99 YES unset up up
Loopback100 3.3.4.100 YES unset up up
I wonder how many loopbacks I can create in a Cisco router. Maybe I'll try that some other time. Good day mates! :)
Thank you.... The use of multiple variables in a single loop is an eye-opener. Thanks again.
pls post the tclsh book
Great post. However I think you should be able to achieve the same objective using the "for" command instead of the "foreach" command like this;
for { set lo 1 } { $lo <= 255 } { incr lo } { puts [ ios_config "interface loopback$lo" "ip address 3.3.4.$lo 255.255.255.255" ] }
One line of Tcl, and you have 255 loopbacks with sequential IP addresses.
Obviously you could adapt this to any subnet you like, and you could use 2 variables if you didn't want your loopbacks to match the IP address.