cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6593
Views
0
Helpful
5
Replies

Router script for Automated router changes

godwin1977
Level 1
Level 1

I am new to the scripting world and do need assistance in developing a script that will assist me to perform the following tasks when executed

1] remove all existing tunnels

2] remove dialer/BVI interface

3] create new DMVPN tunnel

- tunnel x--- MPLS connection to data center

-tunnel y--- Guest traffic

4] Configure interface gi0/2 for broadband connection

- negotiate DHCP addresses

5] remove RIP routing

6] remove EIGRP routing

7] remove route-map pbr-dsl

8] remove route-map pbr-extsrv

9] create route-map for internet traffic over verizon ( pbr-verizon)

- set interface gi0/2

10] create route-map for internet traffic over mpls (pbr-mpls)

- set interface ser0/0

11] apply pbr-verizon to VLANS 10,20,30,40

12] modify NAT statement

13] create inbound and outbound ACL for Gi0/2 interface

- permit udp gre traffic from VIP

- permit tcp any any established

-permit tcp any any eq ftp-data

-permit udp any any eq domain

14] combine all other ACL to ensure no blocking will occur based on all internet traffic from verizon and not mpls

5 Replies 5

Joe Clarke
Cisco Employee
Cisco Employee

I'm not exactly sure what the trigger for these commands will be or what you really mean by step 14.  But, if you know all of the CLI that you want to run, you can string the commands together in an EEM applet or Tcl script.  For an applet:

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command "no int tun0"

...

For Tcl:

if { [catch {cli_open} result] } {

    error $result $errorInfo

}

array set cli $result

if { [catch {cli_exec $cli(fd) "enable"} result] } {

    error $result $errorInfo

}

if { [catch {cli_exec $cli(fd) "config t"} result] } {

    error $result $errorInfo

}

if { [catch {cli_exec $cli(fd) "no int tun0"} result] } {

    error $result $errorInfo

}

...

Joseph I am very grateful for the script you provided.

I forgot to include the information that I outlined below. This is part of the original outlined tasks. I do not know if this script that you provided will  still do the task outlined below:-

Create a EEM script to monitor line-protocol of gi0/2

   - upon line protocol going down for 10 seconds, script changing of VLANS 10,20,30,40 to have pbr-mpls

   -  when line protocol is up for 3 minutes,script changing of VLAN 10,20,30,40 to have pbr-verizon

Do this:

track 1 interface gi0/2 line-protocol

delay down 10

delay up 180

!

event manager applet intf-track-up

event track 1 state up

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command ...

!

event manager applet intf-track-down

event track 1 state down

action 001 cli command "enable"

action 002 cli command "config t"

action 003 cli command ...

Fill in the missing actions that you need.  That should give you what you want.

Joseph,

My question is on syntax when using username and password.  I'm stuck on a script that I found here on the support forums that is using the Expect command. 

My goal is to run the script from a host monitoring server using a device list file to go out and telnet into each one of the routers to run a "Show Inventory" command. 

All the routers are using local AAA with username and password to get to the Privledged Exec mode.  Here's a copy of my script.  I have bolded the parts that I'm curious if correct.  If you could check over it and let me know where my mistakes (If any) are located, I'd appreciate it.  Thanks, Brandon

# Here, we specify all our commands in a list, that we will issue one

# by one at a later time.

set commands {

    "show inventory"

}

# This variable is for a file called hosts.txt that has the hostname/IP

# of all of the routers you are collecting information from.

set device_list [read [open "hosts.txt"]]

# Specify the username and password, as well as what we expect the routers'

# prompt to be.

set username "blah"

set pass "mypassword1234"

set prompt "#"

# This command tells expect not to echo the output to the console.

exp_log_user 0

# We loop through each device in our list, one by one...

foreach device $device_list {

    # Set each device's log file to be the name of the device...

    # (i.e. router1.location.com-log.txt)

    set file_name "$device-log.txt"

    # Assuming you are using PuTTY, and have plink.exe, we initiate the SSH

    # connection

    exp_spawn plink.exe -telnet $device

    # If we see a message asking about the device's host key, accept it.

    expect -re ".*ogin:" {

        exp_send "$username\r"

        exp_send "$pass\r"

    }

    # We log our output from each router to its specified file.

    exp_log_file -a $file_name

    # Loop through each command that we specified earlier.

    foreach cmd $commands {

        expect -re $prompt {

            exp_send "$cmd\r"

            exp_sleep 1

        }

    }

    # Now we enter enable mode for the running-config

    expect -re $prompt {

        send "en\r"

    }

    expect -re ".*assword:" {

        send "$enable_pass\r"

    }

    expect -re $prompt {

        send "term len 0\r"

    }

    expect -re $prompt {

        send "show running-config\r"

    }

    expect -re $prompt {

        exp_send "quit\r"

    }

    # Turn off logging.

    exp_log_file

}

Please start a new thread for your question.

Review Cisco Networking for a $25 gift card