Is there a way to submit a batch of commands to a Cisco router and have them execute from the router?

66

Solution 1

I believe it's possible to copy a file from flash: to running-config, but I am not 100% sure. You may be better off copying the existing running-config to a known-good-startup, copying the config you want on top of startup-config, then reload the router (with, ideally, somneone on site who can be walked through a password-recovery-style recovery, should the new config be broken).

Alternatively, if the relevant config can be comfortably fit in a single TCP frame, you could write some code to issue a reload in 10 command, then a config t and finish off with all relevant config commands, separated by CR NL, in a single frame.

Edit: Then either log on to the router manually or send a second frame with enough commands in it to cancel the reload (the relevant IOS command is reload cancel).

Solution 2

You can do this with a tclsh macro.

Create macro

router#tclsh
router(tcl)# set foo {
+>conf t
+>int f0/1
+>ip addr.....
+>no ip route 0.0.0.0 .....
+>ip route 0.0.0.0 .....
+>exit  
+>exit  
+>}     

Execute and quit tclsh:

router(tcl)#eval $foo
...
router(tcl)#tclq

Test this in a lab to make yourself familiar with tclsh in Cisco routers.

Solution 3

If you have a tftp server that is accessible to the router, you can edit your configuration there, and then load the configuration from the tftp server.

Just be very careful, and have a backup plan in place. If anything goes wrong, you're going to be offline and need to visit yourself, or find someone else local to be your hands.

Solution 4

If you're on a recent IOS, you can use IOS.sh. Once you do term shell, you can separate commands by semicolons on one line, and they'll be run sequentially, just like in bash or similar.

Here's an example one-liner, where I changed out a route:

LAB-6807#show run | incl 111.111
ip route 172.31.111.111 255.255.255.255 Loopback0
LAB-6807#term shell
LAB-6807#conf t; no ip route 172.31.111.111 255.255.255.255 Loopback0; ip route 172.31.111.111 255.255.255.255 Null0; end
Enter configuration commands, one per line.  End with CNTL/Z.
LAB-6807#
*May 18 22:33:27.772: %SYS-5-CONFIG_I: Configured from console by hunter on vty1 (x.x.x.x)
LAB-6807#show run | incl 111.111
ip route 172.31.111.111 255.255.255.255 Null0
LAB-6807#

Solution 5

Do you have telnet access to the router? You can telnet to the router, copy the running config to notepad, make the needed changes, and paste the contents of notepad back into the router from config mode and that should do it.

You may lose your telnet connection temporarily but the router will continue pasting the uploaded config and assuming that the new config works you'll be able to telnet back in and save it to the startup config.

Share:
66

Related videos on Youtube

Bardelman
Author by

Bardelman

Updated on September 17, 2022

Comments

  • Bardelman
    Bardelman over 1 year

    In my app there is a label which once clicked should make the user making a 'like' action on facebook. In this question there is the following piece of code supposed to make that action :

    // Change OBJECT_ID to an actual object id
        Titanium.Facebook.requestWithGraphPath('OBJECT_ID/likes', {}, 'POST', function(e) {
            if (e.success) {
                alert('Success!  From FB: ' + e.result);
            } else {
                if (e.error) {
                    alert(e.error);
                } else {
                    alert('Unkown result');
                }
            }
        });
    

    i have generated an url for the page to be liked from this page but i don't think this is the required 'OBJECT_ID' for that graph request. What is the OBJECT_ID ?!

  • Steve Townsend
    Steve Townsend over 13 years
    As you suspect, the best way to execute a number of commands at once is to merge them into the running-config using copy URI running-config. Naturally, preceded with reload in 10 just in case it doesn't work as expected.
  • Admin
    Admin almost 2 years
    Outstanding solution.