sdolancu has asked for the wisdom of the Perl Monks concerning the following question:
# I always get an exit status of "0" because the ssh was successful. How do I get the "FAIL" ? Help.---- test.sh --- #!/bin/sh echo "Hello world" exit 1 <-- Note that we are forcibly exiting non-zero ---- runme.pl ---- #!/usr/bin/perl local $SIG{CHLD} = sub { wait; } # Shell to the "hosta" and run the script. # Since it will fail, return the word FAIL my $cmd = "ssh hosta -n \"/tmp/test.sh || echo FAIL\"; my ($read, $write, $pid) = spawnMe($cmd); close ( $write ); # Not doing any writes while ( <$read> ) { my $buf = 'X' x 512; if ( my $nread = sysread( $read, $buf, 512 ) ) { my @l = split /\r?\n/, $buffer . $buf; if ($buf !~ /\n$/s ) { $buffer = pop @l; } else { $buffer = ''; } map { print "$_\n"; } @l; } } my $kid = waitpid($pid, WNOHANG); unless ($kid == $pid) { close ($read); $return_code = $?; } else { print "Reaped status: $?" $return_code = $?; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pipe and return status through an "ssh"
by pc88mxer (Vicar) on Jun 10, 2008 at 18:21 UTC | |
|
Re: Pipe and return status through an "ssh"
by Crackers2 (Parson) on Jun 10, 2008 at 18:54 UTC |