RE: autoexpect

From: Ryan West <rwest_at_zyedge.com>
Date: Wed, 30 Sep 2009 15:50:18 -0400

Marko,

Thanks for the PERL script, I'm sure it will come in handy down the road. The scripting part RANCID isn't so bad, you can call to a command file with -x and leverage .cloginrc with clogin to run through your files. I upgraded 30 autonomous APs that way, the only annoying part is that the script depends on rancid-run for any type of regular expression matching, so I had to type out each AP name on a single line.

-ryan

-----------------
Use at your own risk.

------------------------------8<------------------------------
#!/usr/bin/perl -w

#
# Created by Marko Milivojevic <markom_at_markom.info>
#
# No warranty of any sort. Use at your own risk.
#

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

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

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

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

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);
                return;
        };
        if (!($t->login($user, $pass))) {
                printf("Could not log into '%s' as '%s'\n", $host, $user);
                return;
        }
        $t->enable($enab);
        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("/#/");
        $t->print("end");
        print $t->waitfor("/#/");
        $t->print("write memory");
        print $t->waitfor("/#/");
        $t->close();
}

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

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

while (defined ($host = <IF>)) {
        chomp($host);
        if ($host ne "") {
                printf("\n\n\n%s %s %s\n", "-" x 22, $host, "-" x 22);
                ConfigureRouter($host);
        }
}
close(IF);
------------------------------8<------------------------------

--
Marko
CCIE #18427 (SP)
My network blog: http://cisco.markom.info/
Blogs and organic groups at http://www.ccie.net
Received on Wed Sep 30 2009 - 15:50:18 ART

This archive was generated by hypermail 2.2.0 : Sun Oct 04 2009 - 07:42:04 ART