Accessing the Cisco shell with Expect turned out to be not as difficult as it seemed (so far).
#!/usr/bin/perlNo luck getting SSH working... since I don't have any SSH based Ciscos at hand.
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->log_stdout(0); $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; while($redo) { $command->clear_accum(); $command->expect(1, [ qr/More/ => sub { my $comand = shift; print $command "\r"; exp_continue; } ], [ qr/#/ => sub { my $exp = shift; $redo = 0; exp_continue; } ], ); } print $command "exit\r"; $command->soft_close();
Re:SSH on embedded hosts
Beatnik on 2006-07-11T19:31:14
SSH on Juniper works fine! Telnet on Cisco works pretty straightforward using Net::Telnet::Cisco. Net::SSH::Perl works if I patch it and only if I stick to 1 call. (enable + show running-config = 2:( ) Expect seemed the only solution for me. See my previous post on this.