diff --git a/perl-xCAT/xCAT/DSHCLI.pm b/perl-xCAT/xCAT/DSHCLI.pm index df7279d65..8d1e81e93 100644 --- a/perl-xCAT/xCAT/DSHCLI.pm +++ b/perl-xCAT/xCAT/DSHCLI.pm @@ -1076,6 +1076,9 @@ sub fork_fanout_dsh $remote_shell = "$::XCATROOT/sbin/rshell_api"; $rsh_extension='RShellAPI'; $rsh_config{'password'}=$$target_properties{'password'}; + if ($$options{'trace'}) { + $rsh_config{'trace'}=1; + } } # will not set -n for any command, causing problems diff --git a/xCAT-server/lib/perl/xCAT/RShellAPI.pm b/xCAT-server/lib/perl/xCAT/RShellAPI.pm index e8ee09331..141e81d71 100644 --- a/xCAT-server/lib/perl/xCAT/RShellAPI.pm +++ b/xCAT-server/lib/perl/xCAT/RShellAPI.pm @@ -8,6 +8,7 @@ BEGIN } use lib "$::XCATROOT/lib/perl"; use xCAT::MsgUtils; +#use Data::Dumper; ####################################################### =head3 @@ -37,6 +38,9 @@ sub remote_shell_command { } my @tmp; + if ( $$config{'trace'} ) { + push @command, "-v"; + } if ($$config{'user'} && ($$config{'user'} !~ /^none$/i)) { @tmp=split(' ', "-l $$config{'user'}"); push @command, @tmp; @@ -73,11 +77,11 @@ sub run_remote_shell_api { my $node=shift; my $user=shift; my $passwd=shift; + my $verbose=shift; my $args = join(" ", @_); my $t; - my $prompt='.*[\>\#\$]$'; - my $more_prompt='(.*key to continue.*|--More--\s*$)'; - my $verbose=0; + my $prompt='.*[\>\#\$]\s*$'; + my $more_prompt='(.*key to continue.*|.*--More--\s*|.*--\(more.*\)--.*$)'; my $output; eval { @@ -98,7 +102,23 @@ sub run_remote_shell_api { $output.="$errmsg\n"; my $rc=1; - if (not $t) {#ssh failed.. fallback to a telnet attempt + if ($t) { + #Wait for command prompt + my ($prematch, $match) = $t->waitfor(Match => '/login[: ]*$/i', + Match => '/username[: ]*$/i', + Match => '/password[: ]*$/i', + Match => "/$prompt/", + Errmode => "return"); + if ($verbose) { + print "0. prematch=$prematch\n match=$match\n"; + } + + if ($match !~ /$prompt/) { + return [1, $output]; + } + + } else { + #ssh failed.. fallback to a telnet attempt $output.="start Telnet session...\n"; require Net::Telnet; $t = new Net::Telnet( @@ -178,7 +198,7 @@ sub run_remote_shell_api { } } - if (!login_done) { + if (!$login_done) { #Wait for command prompt ($prematch, $match) = $t->waitfor(Match => '/login[: ]*$/i', Match => '/username[: ]*$/i', @@ -205,6 +225,7 @@ sub run_remote_shell_api { } } } + if (!$rc) { $output.=$t->errmsg . "\n"; return [1, $output]; @@ -238,7 +259,7 @@ sub run_remote_shell_api { my $lastline=$t->lastline(); print "---lastline=$lastline\n"; } - ($prematch, $match) = $t->waitfor(Match => "/$more_prompt/", + ($prematch, $match) = $t->waitfor(Match => "/$more_prompt/i", Match => "/$prompt/", Errmode => "return", Timeout=>10); @@ -253,7 +274,7 @@ sub run_remote_shell_api { my $lastline=$t->lastline(); print "lastline=$lastline\n"; } - ($prematch, $match) = $t->waitfor(Match => "/$more_prompt/", + ($prematch, $match) = $t->waitfor(Match => "/$more_prompt/i", Match => "/$prompt/", Match => '/password:\s*$/i', Errmode => "return", @@ -266,17 +287,17 @@ sub run_remote_shell_api { my $error=$t->errmsg(); if ($error) { - $output.="Command $cmd failed: $error\n"; - return [1, $output]; + $output.="Command $cmd failed: $error\n"; + return [1, $output]; } - # remove the first line + # if ($try_more) { - my @data=split("\n", $prematch); - shift @data; + #my @data=split("\n", $prematch); #shift @data; #shift @data; - $prematch=join("\n", @data); + #shift @data; + #$prematch=join("\n", @data); #add a newline at the end if not there my $lastchar=substr($prematch, -1, 1); if ($lastchar ne "\n") { diff --git a/xCAT-server/sbin/rshell_api b/xCAT-server/sbin/rshell_api index 13a4abbcc..aabe637fd 100755 --- a/xCAT-server/sbin/rshell_api +++ b/xCAT-server/sbin/rshell_api @@ -16,19 +16,21 @@ Getopt::Long::Configure("no_pass_through"); my $username; my $passwd; my $help; +my $verbose; if (!GetOptions( 'l|loginname=s' => \$username, 'p|password=s' => \$passwd, 'h|help' => \$help, + 'v|verbose'=> \$verbose, ) || $help || scalar(@ARGV)<2 ) { - print "Usage: rshell_api [-l ] [-p ] \n"; + print "Usage: rshell_api [-v] [-l ] [-p ] \n"; exit; } my $node = $ARGV[0]; -my $output =xCAT::RShellAPI::run_remote_shell_api($node, $username, $passwd, @ARGV[1 .. $#ARGV]); +my $output =xCAT::RShellAPI::run_remote_shell_api($node, $username, $passwd, $verbose, @ARGV[1 .. $#ARGV]); my $rc=0; my $data; if ($output && (@$output > 1)) { diff --git a/xCAT-server/share/xcat/devicetype/EthSwitch/Jun/config b/xCAT-server/share/xcat/devicetype/EthSwitch/Jun/config new file mode 100644 index 000000000..27ecfd8bc --- /dev/null +++ b/xCAT-server/share/xcat/devicetype/EthSwitch/Jun/config @@ -0,0 +1,6 @@ +#configuration file for Juniper switches +[main] +ssh-setup-command= +[xdsh] +pre-command=set cli screen-length 0; +post-command=NULL