$exp = new Expect; $exp->restart_timeout_upon_receive(1); $exp->spawn("ssh -l $nodeuser $ip\r"); $exp->log_file("$logpath/$node_name/$node_name.log", "w"); $exp->expect($timeout, ['-re', 'Password:',sub{ $exp->send("$nodepass\r"); } ], ['-re', 'password:',sub{ $exp->send("$nodepass\r"); } ]); # $exp->send("$nodepass\r"); $exp->expect($timeout,"*"); # $exp->notransfer(1); $exp->expect($timeout, [ timeout => sub { die "login Time Out\n"; } ], [ '-re', "$prompt", sub { my $self = shift; foreach my $priority (sort {$a<=>$b} keys %priority_commands) { my %all_commands = %{$priority_commands{$priority}}; foreach my $commands (keys %all_commands) { $self->clear_accum(); $self->restart_timeout_upon_receive(1); $commands =~ s/[\r\n]//g; $self->send("$commands\n") ; sleep 2; while(1){ sleep(1); $self->expect( [ qr/MORE/i,sub{ $self->send_slow(" "); exp_continue; } ], ['-re', "$prompt",{ last } ]); } sleep 2; } } } ], [ eof => sub { die "ERROR: could not spawn SSH.\n"; } ] ); # $exp->clear_accum(); $exp->expect($timeout,$prompt); $exp->send("exit\n"); $exp->log_file(undef); $exp->soft_close();