Re: [Ssh-sftp-perl-users] Question to BatchMode
Brought to you by:
dbrobins
From: Russ B. <us...@gm...> - 2009-02-17 14:23:27
|
Stefan, eval { my ($stdout, $stderr, $exit) = $ssh->cmd(BashScript); @sdtout_result = split(/\n/, $stdout); @stderr_result = split(/\n/, $stderr); $BashScript_exit_status = $exit; }; if (($BashScript_exit_status ne 0) || ($@)) # then there was a problem if ($@) { print "\$@ = $@\n"; } else { print "ERROR: remote script exit status = $BashScript_exit_status\n"; } foreach (@stderr_result) { print "$_\n"; } } else { # No error was detected foreach (@stdout_result) { print "$_\n"; } } I have not used the register_handler command because the above code gets me what I need. Be sure to program BashScript to exit with a non_zero value if it encounters an error while running on the remote server. You can also program BashScript to run STDERR error free when it encounters no run problem and then test @stderr_result for content. If content exists, something went wrong. The exception might be an FTP command which utilizes the STDERR channel for routine FTP communication. I like to write BashScript to log its own errors remotely and then have it check that log for size. If the remote error log holds content then terminate BashScript with exit(1) instead of exit(0). I hope this helps. I works for me. Russ Brewer On Tue, Feb 17, 2009 at 7:15 AM, Stefan Adling <ste...@gm...>wrote: > I'm running Net::SSH::Perl 1.34. > > I execute a bash-script via ssh on a remote server. > > I register two handles for stdout and stderr: > > $ssh->register_handler( > "stdout", > sub { > my ( $channel, $buffer ) = @_; > print $buffer->bytes; > print LOGFILE $buffer->bytes; > } > ); > $ssh->register_handler( > "stderr", > sub { > my ( $channel, $buffer ) = @_; > print $buffer->bytes; > print LOGFILE $buffer->bytes; > } > ); > > Then is send my command with: > > $ssh->cmd("BashScript"); > > wait until it finishes. > > The question I have is: > > How do I detect a connection loss? > > The script on the remote server my take a very long time without any > activity on the console. > > I have tried invoking my connection with "options => [ > "ServerAliveInterval 15 ServerAliveCountMax 10" ]" or "options => [ > "BatchMode yes" ]". However whenever I test it, by pulling out the > network cable while the script runs, it just sits there. The longest I > have waited is 45 min until I aborted manually. > > Shouldn't the connection be checked every 300 seconds with "BatchMode yes"? > > Any help would be appreciated. > > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, > CA > -OSBC tackles the biggest issue in open source: Open Sourcing the > Enterprise > -Strategies to boost innovation and cut costs with open source > participation > -Receive a $600 discount off the registration fee with the source code: > SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Ssh-sftp-perl-users mailing list > Ssh...@li... > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > |