diff --git a/xCAT-server/lib/perl/xCAT/SSHInteract.pm b/xCAT-server/lib/perl/xCAT/SSHInteract.pm index d673c8fc7..ea7b7d9f9 100644 --- a/xCAT-server/lib/perl/xCAT/SSHInteract.pm +++ b/xCAT-server/lib/perl/xCAT/SSHInteract.pm @@ -1,8 +1,10 @@ package xCAT::SSHInteract; use Exporter; use Net::Telnet; +BEGIN { + our @ISA = qw/Exporter Net::Telnet/; +}; use strict; -our @ISA = qw/Exporter Net::Telnet/; our @EXPORT_OK = (); use IO::Pty; use POSIX; @@ -21,11 +23,11 @@ sub _startssh { } #in child $tty = $pty->slave or die "$!"; + $pty->make_slave_controlling_terminal(); $tty_fd = $tty->fileno or die "$!"; close($pty); open STDIN, "<&", $tty_fd; open STDOUT,">&",$tty_fd; - $pty->make_slave_controlling_terminal(); close($tty); my @cmd = ("ssh","-o","StrictHostKeyChecking=no"); if ($args{"-nokeycheck"}) { @@ -50,10 +52,13 @@ sub new { delete $args{"-username"}; delete $args{"-password"}; my $nokeycheck = $args{"-nokeycheck"}; - if ($nokeycheck) { delete $args{"-nokeycheck"}; } - my $self = Net::Telnet->new(%args); + delete $args{"-nokeycheck"}; + my $self = $class->Net::Telnet::new(%args); _startssh($self,$pty,$username,$host,"-nokeycheck"=>$nokeycheck); - my ($prematch,$match) = $self->waitfor([Match => $args{prompt},'/password:/i',]) or die "Login Failed: ",$self->lastline; + my $promptex = $args{Prompt}; + $promptex =~ s!^/!!; + $promptex =~ s!/\z!!; + my ($prematch,$match) = $self->waitfor(Match => $args{Prompt},Match=>'/password:/i') or die "Login Failed: ",$self->lastline; if ($match =~ /password:/i) { #$self->waitfor("-match" => '/password:/i', -errmode => "return") or die "Unable to reach host ",$self->lastline; $self->print($password); @@ -64,7 +69,13 @@ sub new { if ($nextline =~ /^password:/ or $nextline =~ /Permission denied, please try again/) { die "Incorrect Password"; } - } + } elsif ($match =~ /$promptex/) { + *$self->{_xcatsshinteract}->{_atprompt}=1; + } return bless($self,$class); } +sub atprompt { + my $self=shift; + return *$self->{_xcatsshinteract}->{_atprompt}; +} 1; diff --git a/xCAT-server/lib/xcat/plugins/blade.pm b/xCAT-server/lib/xcat/plugins/blade.pm index 248bf4854..e2393c6a9 100644 --- a/xCAT-server/lib/xcat/plugins/blade.pm +++ b/xCAT-server/lib/xcat/plugins/blade.pm @@ -4038,7 +4038,7 @@ sub clicmds { Prompt=>'/system> $/' ); my $Rc=1; - if ($t) { #we sshed in, but we may be forced to deal with initial password set + if ($t and not $t->atprompt) { #we sshed in, but we may be forced to deal with initial password set my $output = $t->get(); if ($output =~ /Enter current password/) { $t->print($currpass); @@ -4058,7 +4058,7 @@ sub clicmds { } } $t->waitfor(match=>"/system> /"); - } else {#ssh failed.. fallback to a telnet attempt for older AMMs with telnet disabled by default + } elsif (not $t) {#ssh failed.. fallback to a telnet attempt for older AMMs with telnet disabled by default require Net::Telnet; $t = new Net::Telnet( Timeout=>15, @@ -4973,7 +4973,7 @@ sub dompa { $rc = 1; $args = []; } else { - $result = clicmds($mpa,$user,$pass,$node,$slot,args=>\@exargs); + $result = clicmds($mpa,$user,$pass,$node,$slot,cmds=>\@exargs); $rc |= @$result[0]; $args = @$result[1]; } @@ -5024,7 +5024,7 @@ sub dompa { if ($mptype eq "cmm") { # For the cmm, call the rscanfsp to discover the fsp for ppc blade my @telargs = ("rscanfsp"); - clicmds($mpa,$user,$pass,$node,$slot,args=>\@telargs); + clicmds($mpa,$user,$pass,$node,$slot,cmds=>\@telargs); } } }