Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Beatnik (493)

  (email not shown publicly)

A 29 year old belgian who likes Mountain Dew, Girl Scout Cookies, Tim Hortons French Vanilla Flavoured Cappucinno, Belgian beer, Belgian chocolate, Belgian women, Magners Cider, chocolate chipped cookies and Perl. Likes snowboarding, snorkling, sailing and silence. Bach can really cheer him up! He still misses his dog.

Project Daddy of Spine [], a mod_perl based CMS.

In his superhero time (8.30 AM to 5.30 PM), he works on world peace.

Journal of Beatnik (493)

Monday July 10, 2006
03:09 PM

Expecting Cisco

[ #30245 ]
Accessing the Cisco shell with Expect turned out to be not as difficult as it seemed (so far).


use Expect;
use strict;
my $device = $ARGV[0];
my $password = $ARGV[1];
my $enable_password = $ARGV[2];
my $timeout = 10;
my $command = Expect->spawn("telnet $device");
$command->expect($timeout, -re => "Password:") or die("Failed to get password prompt");
print $command "$password\r";
print $command "enable\r";
$command->expect($timeout, -re => "assword") or die("Did not get a password prompt\n");
print $command "$enable_password\r";
print $command "show log\r";
my $redo = 1;
{ $command->clear_accum();
               [ qr/More/ => sub { my $comand = shift; print $command "\r"; exp_continue; } ],
               [ qr/#/ => sub { my $exp = shift; $redo = 0; exp_continue; } ],
print $command "exit\r";

No luck getting SSH working... since I don't have any SSH based Ciscos at hand.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • If Cisco is anything like Juniper/Netscreen (and in my experience it is :) I wouldn't bother trying to use Perl's own Net::SSH modules. Someone somewhere plays fast and loose with the specs, and I was never able to get the connection to work.

    But using Expect to drive a telnet or ssh session to a Juniper box works very well. I spoke to btrott at the time (this was about 5 years ago) he said that he didn't have time to maintain Net::SSH as best it deserved any more.