First off I'm new to this site so please be kind :-)
I have wrote a script which will be loaded on to several remote machines. The script executes Linux commands using backticks and sets an exit status depending upon how the script progressed. Unfortunately I have to use the backtick method to return the output of the executed command so that I can distinguish between a truely successful outcome and one where a 0 exit code is returned but the outcome is not actually a success. This means I can't use '$?' to check for a correct exit status.
As this script exists on multiple remote machines, I tried to code another script to launch the remote code and return the exit status as set in 'remote.script' using Net::SSH:Perl. The problem is that Net::SSH::Perl also returns stdout and appears to "grab" stdout from the remote script. This has the effect that the remote script can not use the output of the Linux executed commands for error checking as stdout is directed to 'local.script'.###remote.script### $result1=`DB_COMPILE $from $to`; if ($result1 =~ m/0 errors, 0 warnings/) { <<SUCCESS - SOME CODE>> exit_status("Success\n","0"); }else { exit_status("DB_COMPILE failed\n","1"); } sub exit_status { my $description=shift; my $status=shift; print "$description\n"; exit("$status"); }
Is there a way to turn off Net::SSH::Perl's ability to grab stdout from the remote session whilst still enabling me to grab the exit status? I have read the docs on CPAN, confused myself no end and then googled this problem, but still can't find an answer. Normally this excellent Perl module would be a godsend, but just not in this instance where I need stdout to stay on the remote machine.###local.script### %codes=('0' => 'Success', '1' => 'General failure',); my $ssh = Net::SSH::Perl->new("$ip"); $ssh->login ($user, $pass); ($exit) = $ssh->cmd("Remote.script"); $description=$codes{"$exit"}; print "EXIT STATUS: $exit $description\n";
In reply to Turn off stdout in Net::SSH::Perl by cstrong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |