DNS server changes - challange

we need the following lines changed in 500+ routers.  The hard part is each router has one unique address.  Can this be scripted somehow in NCM?


Router 1
ip dhcp pool DHCPPOOL1
 no dns-server 10.20.20.1 192.168.40.25 192.168.40.26
!
Router 2
ip dhcp pool DHCPPOOL1
 no dns-server 10.30.30.1 192.168.40.25 192.168.40.26

The two common DNS servers need to be removed "192.168.40.25 192.168.40.26".
The other IP address is unique to each router and can't be removed without impacting DNS.

Issusing the following, just removed the entire DNS line from the DHCP pool. 

ip dhcp pool MBO_LAN
 no dns-server 192.168.40.25 192.168.40.26

Is there a way to remove the 192.168.40.25 192.168.40.26 while leaving the unique in place?
So, The end result needs to look like this:

Router 1
ip dhcp pool DHCPPOOL1
  dns-server 10.20.20.1
!
Router 2
ip dhcp pool DHCPPOOL1
  dns-server 10.30.30.1

  • Any one ever respond, or did you figure out how to script this?

  • This can't be done simply in NCM.  I would do this in Expect as a first timer.

    Here would be how (this is depending on the fact there is only ONE dhcp scope configured and that you want the first IP listed):

    #!/usr/bin/expect

    #set variables that are called by prefixing dollar signs

    set pass "password"

    set deviceList {hostnames or ips seperated by spaces}

    foreach host [split $deviceList] {

         spawn ssh $host

         expect "word:"

         send "$pass\r"

         expect "#"

         send "show run | i dns-server\r"

         expect "#"

         set firstIP "blank"

         regexp {([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})} $expect_out(buffer) firstIP

         if {$firstIP != "blank"} {

              send "config t\r"

              expect ")#"

              send "ip dhcp pool DHCPPOOL1\r"

              expect ")#"

              send "no dns-server\r"

              expect ")#"

              send "dns-server $firstIP\r"

              expect ")#"

              send "end\r"

              expect "#"

              send "wr\r"

              expect "#"

              puts "$host Successfully updated DHCP scope"

         } else {

              puts "$host Failed to parse IP"

         }

         send "exit\r"

    }