Hi Monks,

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.

###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"); }
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'.
###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";
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.

In reply to Turn off stdout in Net::SSH::Perl by cstrong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.