Okay, it does not seem that you actually need to kill anything here, and it's not about any prompts. Prior to installing any modules let's try to understand what do you want first, and then why your code does not work as you want it to.
The task seems to be to launch a JBoss server on a remote machine via SSH, isn't it? As far as I understand, you took sh /a/bbb/JBoss7/jboss-as-7.1.1.Final/bin/standalone.sh -b 0.0.0.0 & from a manual. When you, logged in to xx.xx.xx.xx as buildteam user, run it interactively — the JBoss server is started in the background, and you get your command prompt back.
What happens if we try to run ssh buildteam@xx.xx.xx.xx sh ... & interactively from your workstation? Yep, JBoss server is started in the background, but the devil is in the details — as & sends to the background not only a standalone.sh script but your interactive SSH session instead. It is hardly what you want because if the SSH session gets terminated (e.g., you turned off your workstation or there is a network disruption) so will your server, and you want your JBoss to run independently.
The magic & is a shell instruction. So, when shell parses your command and encounters an ampersand it launches the process in the background (showing something like [1] 9529 among other things, where 1 is a shell job ID and 9529 is the actual PID). The problem is, what shell gets to interpret this &? You need to escape it, with a backslash or shell quotes, if you want to pass it as it is to the remote shell. In this case I'd prefer quotes to improve readability:
ssh buildteam@xx.xx.xx.xx "sh .../standalone.sh ... &"
Then, back to our beloved Perl and its system() call. What happens if you put & in its argument? It's a shell metacharacter so system("... &") will invoke a shell to run the command. As it happens when you run the command interactively, the SSH process is sent to background, and you need the same quoting mechanism to send standalone.sh to background instead. So, to make our code pretty let's use cool q{} Perl operator (beware: it does not interpolate $vars in the string, just like '' operator so use qq{} if you need any substitutions, but qq{} will need \@remote again):
system(q{ssh buildteam@xx.xx.xx.xx "sh .../standalone.sh ... &"});
And, as a finishing touch, let's add &>/dev/null shell instruction which will get rid of all the output from standalone.sh (we don't care so why litter our terminal?):
system(q{ssh buildteam@xx.xx.xx.xx "sh .../standalone.sh ... &>/dev/nu
+ll &"});
So, to sum up: system() launches shell, shell parses the command in q{...}, doesn't see & there as instruction, and launches ssh, which launches sh on the remote server xx.xx.xx.xx as a buildteam user, which parses the command in "...", sees & there and, finally, sends .../standalone.sh -b 0.0.0.0 to background on xx.xx.xx.xx machine. Then the control gets back to Perl. Just UNIX things, eh?
PS However the thing which baffles me is why you don't get your Server started message. As you didn't check system() call result the execution must continue regardless any errors, where is the message then? I don't have JBoss around but checked similar code on my workstation — I get the message every time. Is it use autodie;, or maybe you just loose Server started in the standalone.sh output? Nevertheless the rest of my babble still stands. |