From 0a2f1478d6c04aad602b51370616f52cb243ae0f Mon Sep 17 00:00:00 2001 From: sakolish Date: Thu, 6 Dec 2007 16:29:08 +0000 Subject: [PATCH] Stream back Expect STDOUT/STDERR through daemon from PPCcli::connect - Line #67 git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@140 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/PPCcli.pm | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/PPCcli.pm b/perl-xCAT-2.0/xCAT/PPCcli.pm index 03c554ace..637f7d114 100644 --- a/perl-xCAT-2.0/xCAT/PPCcli.pm +++ b/perl-xCAT-2.0/xCAT/PPCcli.pm @@ -74,6 +74,7 @@ sub connect { my $timeout = 10; my $success = 0; my $pwd_sent = 0; + my $expect_log; ################################################## # Shell prompt regexp based on HW Type @@ -83,7 +84,7 @@ sub connect { ivm => "\\\$ \$" ); ################################################## - # Get userid/password based on Hardware Conrol Pt + # Get userid/password ################################################## my @cred = xCAT::PPCdb::credentials( $server, $hwtype ); @@ -106,19 +107,34 @@ sub connect { $ssh->slave->stty(qw(sane -echo)); ################################################## - # exp_internal(1) sets exp_internal debugging. - # This is similar in nature to its Tcl counterpart + # exp_internal(1) sets exp_internal debugging + # to STDERR. + ################################################## + $ssh->exp_internal( $verbose ); + + ################################################## + # Redirect STDERR to variable ################################################## if ( $verbose ) { - $ssh->exp_internal(1); + close STDERR; + if ( !open( STDERR, '>', \$expect_log )) { + return( "Unable to redirect STDERR: $!" ); + } } ################################################## - # log_stdout(0) disables logging to STDOUT. This - # corresponds to the Tcl log_user variable. + # log_stdout(0) disables logging to STDOUT. + # This corresponds to the Tcl log_user variable. ################################################## - if ( !$verbose ) { - $ssh->log_stdout(0); + $ssh->log_stdout( $verbose ); + + ################################################## + # Redirect STDOUT to variable + ################################################## + close STDOUT; + if ( !open( STDOUT, '>', \$expect_log )) { + return( "Unable to redirect STDOUT: $!" ); } + unless ( $ssh->spawn( "ssh", $parameters )) { return( "Unable to spawn ssh connection to server" ); } @@ -176,7 +192,8 @@ sub connect { $hwtype, $server, $cred[0], - $cred[1] ); + $cred[1], + \$expect_log ); } ########################################## # Failed logon - kill ssh process @@ -805,3 +822,4 @@ sub power_cmd { 1; +