in reply to Perl (Net::SSH::Perl) script sometimes hangs while running remote command but shell script works

I have observed that the script hangs rarely
That indicates a bug somewhere. Use strace or some similar tool to discover what every component is doing. Your Java application or the wrapper may be waiting for something.

You can also enable debugging on Net::OpenSSH to see what is happening at the perl level:

$Net::OpenSSH::debug = -1;

are bash scripts faster when it comes to execution than its perl counterpart?

Perl code is usually faster than shell code. On scripts that invoke external commands, there is usually no difference between the two.

If your Perl script is slower it probably means that it is doing things in a different way.

In some cases, I also notice that a bash script prints messages that my perl script doesn’t.

Net::OpenSSH provides you several methods to redirect or capture the stdio streams of the remote process. You have to pick the ones that you need.

For instance, I had an issue where deployment was not happening on machine A. On investigation, I came to know that Java was not deployed. This I came to know when I logged into machine A and ran the bash script that my perl script was calling. I thought of triggering the same bash script using another bash script remotely from the same machine where my perl script was. I did see the Java missing message. Why is it so? Why is my perl script unable to capture the error message despite using ‘$ssh->error’ in my script?

That means that your wrapper script is hiding it. $ssh->error returns an error code when the remote command exits with a non zero value.

  • Comment on Re: Perl (Net::SSH::Perl) script sometimes hangs while running remote command but shell script works
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Perl (Net::SSH::Perl) script sometimes hangs while running remote command but shell script works
by Technext (Acolyte) on Jun 19, 2015 at 08:46 UTC
    Thanks for the help salva! As far as debugging the script (when it hangs) is concerned, I’ll use strace.

    For the issue where bash was printing error message but my perl script wasn’t, I figured out the mistake I was committing. Instead of

    my ($stdout) = $ssh->capture2("~/release/$wrapper");

    I should have used

    my ($stdout, $errput) = $ssh->capture2("~/release/$wrapper");

    I was only checking stdout earlier :)

      There is one issue that i noticed today. If i use the following code, it dies after printing error message. Obviously, the stdout will not be printed

      die "Error: $errput\n" if $errput; printf "Output: $stdout\n" if $stdout;
      Problem is when i reverse the lines as shown below, it prints the output and then dies but does not print the error message.
      printf "Output: $stdout\n" if $stdout; die "Error: $errput\n" if $errput;
      How can i make it print the stdout and the error message both?