cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
612
Views
10
Helpful
8
Replies

Need help with a script

amb1s1
Level 1
Level 1
I have to config 187 routers by march and I would like to see if anybody can help creating an script that would help me do this in a most efficient way.
The way I'm doing it is by having a template that most of the config are the same ecept for the loop interface, both primary and backup line, interface
for one access point and couple of more configs. Anybody up to this? thanks
8 Replies 8

mtsb
Level 1
Level 1

The best way is to use TCL scripts to generate the configs. If the configs are same except say loopback interface tcl can be used but if they have unique commands on every router then you have to configure them manually. Give a snip of configs on few router so that we can conclude if we can do it in efficient way

All commands are the same, the only thing that change is, loopback, G0/0, G0/1, s0/0, RIP network address, BGP neighbor address, ip route next hop, hostname, but all the same commands. DO you have a sample script that I play around? I would post the template tomorrow morning because I'm not at work at this time, but it would be nice to see a sample.

How about this?

******************************************************
unset config_router1
unset config_router2

#set string     "hostname loopback G0/0       S0/0      RIP        BGP      next_hop"
set Router(1) "router1  10.1.1.1    20.1.1.1  30.1.1.2  40.0.0.0 50.1.1.1 60.1.1.1"
set Router(2) "router2  10.1.2.1    20.1.2.1  30.1.2.2  40.0.0.0 50.1.2.1 60.1.2.1"

for {set i 1} {$i<3} {incr i} {

append config_router$i "hostname [lrange $Router($i) 0 0]\n
                       interface loopback0\n
                       ip address [lrange $Router($i) 1 1] 255.255.255.255 \n
                       interface gig 0/0\n
                       ip address [lrange $Router($i) 2 2] 255.255.255.0 \n
                       interface Serial 0/0\n
                       ip address [lrange $Router($i) 3 3] 255.255.255.0 \n
                       router rip\n
                       network [lrange $Router($i) 4 4]\n
                       router bgp 1\n
                       neighbor [lrange $Router($i) 5 5] remote-as 100\n
                       ip route [lrange $Router($i) 6 6] 255.255.255.255 70.1.1.1"
                      
}                     

puts $config_router1
puts $config_router2

*****************************************

Output will be something like this...

puts $config_router1
puts $config_router2
router2  10.1.2.1 20.1.2.1  30.1.2.2 40.0.0.0 50.1.2.1 60.1.2.1
expect1.311> expect1.312> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> expect1.313> expect1.314> hostname router1

                       interface loopback0

                       ip address 10.1.1.1 255.255.255.255

                       interface gig 0/0

                       ip address 20.1.1.1 255.255.255.0

                       interface Serial 0/0

                       ip address 30.1.1.2 255.255.255.0

                       router rip

                       network 40.0.0.0

                       router bgp 1

                       neighbor 50.1.1.1 remote-as 100

                       ip route 60.1.1.1 255.255.255.255 70.1.1.1
expect1.315> hostname router2

                       interface loopback0

                       ip address 10.1.2.1 255.255.255.255

                       interface gig 0/0

                       ip address 20.1.2.1 255.255.255.0

                       interface Serial 0/0

                       ip address 30.1.2.2 255.255.255.0

                       router rip

                       network 40.0.0.0

                       router bgp 1

                       neighbor 50.1.2.1 remote-as 100

                       ip route 60.1.2.1 255.255.255.255 70.1.1.1
expect1.316>

From here on I think you can change a bit according to your requirements and generate the config string for each router. Instead of append you can save in an individual file and save at current location. Then copy them into your routers using tftp copy.

Please rate if you feel the answer is useful

HTH,

Madhu

How do I add the rest of the config on this scrip? and I would like to know if there is a way to save the output to a textfile? Thanks for your help, I really appreciate

In the script I have provided I have shown how to generate the configs for 2 routers. The variables Router(1) and Router(2) are the input variable which hold to hostname, ip address of interfaces and all user inputs. The commented line above indicates what each element in that variable refers to. For eg , the first element refers to the router hostname, second refers to the ip address of hte loopback interface and so on. YOu will have to modify this variable according to your requirements. Again you will have to have similar such input variable for all 187 routers you are going to configure. Change the loop interation to 188 to run that many times. Finally instead of saving in variable and printing them, you can open a file, dump config into that file and save it in current location so that you can refer to them later.

If you have a server in which tcl is installed and from there if  you can reach your routers them you can telnet to them directly and config the routers.

Hi, I'm making a lots of progress on my script, but I'm encounter a problem when I

have the secret password $1$oe7A$/L7LibyrC. the script think that 1,o and / are variable. How can make this happen? Thanks

I was able to figure out how to add the enable secret by adding the backslah before \$.

I finished my script that by the way I made GUI since my coworker want it that way.

I just want to make the GUI more simple, like I have the provider ip and my ip address.

Example if my my ip address is 68.23.234.2 my provider ip address is always going to

be one below my ip address in this case is 68.23.234.1. So I would like to know how can

I do that since there is no simple formula to do that. Also, I don't know if you are familiar with

GUI, but I don't know how to move the labels to the side to make more room for the other

routers config. If you see my script, I only have one router, but I would like to acommodate

a least for 5 routers. If you can help me with that I will appreciate. This is my script


#This function will be executed when the button is pushed
proc push_button {} {
set  c1 [.host get]
set  c2 [.loop5 get]
set  c3 [.tun0 get]
set  c4 [.g0/0desc get]
set  c5 [.g0/0addr get]
set  c6 [.g0/1Addr get]
set  c7 [.s0des get]
set  c8 [.s0/035 get]
set  c9 [.dhcpex get]
set  c10 [.dhcpnet get]
set  c11 [.dhcpdro get]
set  c12 [.pipg get]
set  c13 [.sitenet get]
set  c14 [.snmplocat get]
        set config "
      

hostname $c1
!
interface Loopback5
description Lo5_$c1
ip address $c2 255.255.255.255
!
interface Tunnel0
ip address 172.20.$c3 255.255.252.0
!
interface Tunnel1
ip address 172.23.$c3 255.255.252.0
!
interface GigabitEthernet0/0
description $c4
ip address $c5 255.255.255.XX
!
interface GigabitEthernet0/1
ip address $c6 255.255.255.248
!
interface Serial0/0/0
description Serial0_0_0_VB_CID_ $c7 _256K_Port_ $c1 _RTR
!
interface Serial0/0/0.35 point-to-point
ip address $c8 255.255.255.252
!
ip dhcp excluded-address  $c9
!
ip dhcp pool DM_Access
   network $c10 255.255.255.248
   dns-server 172.20.50.215 172.20.50.217
   default-router $c11
   lease 0 2
!

!
router bgp 65534
neighbor 172.20.224.1 remote-as 65533
neighbor 172.20.224.1 soft-reconfiguration inbound
neighbor 172.20.224.1 distribute-list 67 out
neighbor 172.23.224.1 remote-as 65532
neighbor 172.23.224.1 soft-reconfiguration inbound
neighbor 172.23.224.1 distribute-list 67 out
neighbor $c12 remote-as 65000
neighbor $c12 soft-reconfiguration inbound
neighbor $c12 distribute-list 10 out
neighbor $c12 distribute-list 88 in
network $c2 mask 255.255.255.255
network $c6 mask 255.255.255.248
aggregate-address $c6 255.255.255.248 summary-only
!
ip route 0.0.0.0 0.0.0.0 172.23.224.1 250
ip route $c13 255.255.255.0 Serial0/0/1
ip route 172.209.100.103 255.255.255.255 XX.XX.XX.XX
ip route 172.205.41.190 255.255.255.255 XX.XX.XX.XX
!
snmp-server location $c14
interface GigabitEthernet0/0
no shut
interface GigabitEthernet0/1
no shut
interface Serial0/0/0
no shut
interface Serial0/0/1
no shut
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
router rip
version 2
redistribute static
network 10.0.0.0
network $c8
distance 18
no auto-summary


interface Serial0/0/0.35 point-to-point
ip summary-address rip $c13 255.255.255.0
!
ip route 0.0.0.0 0.0.0.0 Serial0/0/0.35 240
!
crypto key generate rsa usage-keys mod 1024"
set out [open "$c1.txt" a]
puts $out "$config"
.txt insert end "$config"
}

#Global Variables
set age 10

#GUI building
frame .frm -relief groove
label .lab -text "Router 1"
label .lab1 -text "Enter Hostname:"
entry .host
label .lab2 -text "Enter Loopback5:"
entry .loop5
label .lab3 -text "Enter Tunnel0:"
entry .tun0
label .lab4 -text "Enter G0/0 Description:"
entry .g0/0desc
label .lab5 -text "Enter G0/0 Address:"
entry .g0/0addr
label .lab6 -text "Enter G0/1 Address:"
entry .g0/1Addr
label .lab7 -text "Enter S0/0/0 Description:"
entry .s0des
label .lab8 -text "Enter S0/0/0.35 Address:"
entry .s0/035
label .lab9 -text "Enter DHCP Exclude-Address:"
entry .dhcpex
label .lab10 -text "Enter DHCP Pool Network:"
entry .dhcpnet
label .lab11 -text "Enter DHCP Default Route:"
entry .dhcpdro
label .lab12 -text "Enter PIP Provider Gateway:"
entry .pipg
label .lab13 -text "Enter Store  Network 10.si.te.0:"
entry .sitenet
label .lab14 -text "Enter snmp-server location:"
entry .snmplocat
button .but -text "Push Me" -command "push_button"
#Text Area
frame .textarea
text .txt -yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set" \
-width 115 -height 5
scrollbar .srl_y -command ".txt yview" -orient v
scrollbar .srl_x -command ".txt xview" -orient  h

#Geometry Management
pack .lab -in .frm
pack .lab1 -in .frm
pack .host -in .frm
pack .lab2 -in .frm
pack .loop5 -in .frm
pack .lab3 -in .frm
pack .tun0 -in .frm
pack .lab4 -in .frm
pack .g0/0desc -in .frm
pack .lab5 -in .frm
pack .g0/0addr -in .frm
pack .lab6 -in .frm
pack .g0/1Addr -in .frm
pack .lab7 -in .frm
pack .s0des -in .frm
pack .lab8 -in .frm
pack .s0/035 -in .frm
pack .lab9 -in .frm
pack .dhcpex -in .frm
pack .lab10 -in .frm
pack .dhcpnet -in .frm
pack .lab11 -in .frm
pack .dhcpdro -in .frm
pack .lab12 -in .frm
pack .pipg -in .frm
pack .lab13 -in .frm
pack .sitenet -in .frm
pack .lab14 -in .frm
pack .snmplocat -in .frm
pack .frm
pack .but
grid .txt   -in .textarea -row 1 -column 1
grid .srl_y -in .textarea -row 1 -column 2 -sticky ns
grid .srl_x -in .textarea -row 2 -column 1 -sticky ew
pack .textarea

Hi,

I have no idea about the GUI stuff you are talking about. I can help you on TCL scripting side. May be others in this forum can help you on this.


Thanks,

Madhu

Review Cisco Networking products for a $25 gift card