Mass Change on Routers

There was, many times repeated, question on GroupStudy today. How do I deploy my changes on many routers? Are there any tools that do that? The answer to that question is – sure there are. Many of them.

Some cost money, some are free, some offer good change control, rollback, etc. What is common with all of them is that often, one doesn’t have the luxury of having them around when one needs them. For those cases, something quick-and-dirty just may be enough. The Perl script below does just that. It will pick up the list of commands to run from a file, it will pick up the list of routers from another file. It will then telnet to all routers in sequence and deploy your set of commands. There is very rudimentary error checking, so… use at your own risk.

This has been written in 15 minutes and is probably full of bugs and really bad code, but… it works for me.

#!/usr/bin/perl -waitfor

use Net::Telnet::Cisco();
use strict;

my ($host, $user, $pass, $enab, $cmdf, $lstf, @cmds);

$cmdf = "commands.txt";
$lstf = "list.txt";

$user = "USERNAME";
$pass = "PASSWORD";

sub ConfigureRouter {
        my ($t, $host, $cmd);

        $host = $_[0];

        if (!($t = Net::Telnet::Cisco->new(Host => "$host", Errmode => "return"))) {
                printf("Could not open session to '%s'n", $host);
        if (!($t->login($user, $pass))) {
                printf("Could not log into '%s' as '%s'n", $host, $user);
        print("Login successful. Setting up ");
        $t->print("terminal length 0");
        print $t->waitfor("/#/");
        $t->print("conf t");
        foreach $cmd (@cmds) {
                print $t->waitfor("/#/");
                $t->printf("%s", $cmd);
        print $t->waitfor("/#/");
        print $t->waitfor("/#/");
        $t->print("write memory");
        print $t->waitfor("/#/");

# Main Body
open (CF, "< " . $cmdf) or die "Can't read the command file '$cmdf'";
@cmds = <CF>;

open (IF, "< " . $lstf) or die "Can't read the router list file '$lstf'";

while (defined ($host = <IF>)) {
        if ($host ne "") {
                printf("nnn%s %s %sn", "-" x 22, $host, "-" x 22);

Did I say that you should use this at your own risk?

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>