#$Net::OpenSSH::debug = ~0;
my $ip = shift @ARGV || die "usage: $0 IP command[ command ...]\n";
+$ip = $1 if `host $ip` =~ m/has address (\S+)/;
my @commands = @ARGV;
@commands = <DATA> unless @commands;
warn "\n## ssh $ip\n";
-my $ssh = Net::OpenSSH->new($ip, user => $login, passwd => $passwd);
+my $ssh = Net::OpenSSH->new($ip, user => $login, passwd => $passwd, default_ssh_opts => [-o => "StrictHostKeyChecking=no"]);
my ($pty ,$pid) = $ssh->open2pty();
if ( ! $pty ) {
warn "ERROR: can't connect to $ip, skipping";
sub send_pty {
my $string = shift;
- sleep 0.1; # we really need to wait for slow PowerConnect 5324
+ sleep 0.05; # we really need to wait for slow PowerConnect 5324
foreach (split //, $string) {
print STDERR "[$_]" if $debug;
syswrite $pty, $_;
#$pty->flush;
- sleep 0.05;
+ sleep 0.01;
sysread $pty, my $echo, 1;
print STDERR $echo;
my ($ip, $hostname, $command, $buff) = @_;
return unless $command;
+ return if $ENV{NO_LOG};
my $file = "${ip}_${hostname}_${command}.log";
open my $log, '>', $file;
} 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;
# 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';
}
}