our $passwd;
our $debug = $ENV{DEBUG} || 0;
+use lib '.';
require 'config.pl';
#$Net::OpenSSH::debug = ~0;
my ($ip, $hostname, $command, $buff) = @_;
return unless $command;
+ return if $ENV{NO_LOG};
my $file = "${ip}_${hostname}_${command}.log";
open my $log, '>', $file;
}
my $command;
+my @commands_while = ( @commands );
-while(1) {
+while() {
my $data;
my $read = sysread($pty, $data, 1);
print STDERR $data;
} elsif ( $buff =~ m/Password:/ ) {
send_pty "$passwd\n";
$buff = '';
- } elsif ( $buff =~ m/([\w\-]+)#$/ ) {
+ } elsif ( $buff =~ m/([\w\-\(\)]+)#$/ ) {
my $hostname = $1;
if ( $buff ) {
save_log $ip, $hostname, $command, $buff;
$buff = '';
}
- if ( $command = shift @commands ) {
+ if ( $command = shift @commands_while ) {
$command =~ s/[\n\r]+$//;
send_pty "$command\n";
$buff = '';
# nop
} elsif ( $buff =~ m/^[\r\n]+[\w\-]+>$/ ) {
send_pty "enable\n";
+ } elsif ( $buff =~ m{\QOverwrite file [startup-config] ?[Yes/press any key for no]....\E} ) {
+ send_pty "y";
+ $buff = '';
+ } elsif ( $buff =~ s{Management access will be blocked for the duration of the transfer.*Are you sure you want to start\? \(y/n\) }{}s ) {
+ send_pty 'y';
}
}
__DATA__
+show system
show arp
show vlan
show running-config
show bridge address
+show interfaces status
+