For what it's worth, it's trivial to use perl to do this. This is the kind of stuff that perl was made for.<br>Wrote up some example code below. If you want to do match exit codes with commands, you'd use the return codes of fork() and wait() which are the created and deceased pids. (created hashmap mapping pids to commands or something)<br>
<br>foreach $command (@mycommands)<br>{<br> if(fork() == 0)<br> { #ischild<br> exec $command;<br> }<br>}<br><br>while(wait() != -1)<br>{<br> print "return code: " , $? >> 8;<br>}<br><br>
<br><br><div class="gmail_quote">On Fri, Jun 15, 2012 at 8:09 AM, David Lee Lambert <span dir="ltr"><<a href="mailto:davidl@lmert.com" target="_blank">davidl@lmert.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<u></u>
<div bgcolor="#ffffff" text="#000000">
Thanks for all the replies.<br>
<br>
Looking at the bash manpage, it looks like "%+" and "fg" are the tools
I need. I just need to see if they can be used to build a maintainable
idiom.<br>
<br>
The script I'm writing would be deployed on RHEL5, and the target
environment is already running JBoss. The languages I could use,
ordered from most-acceptable to least-acceptable (to management), are:<br>
<br>
1. Java (except then I might need another script to set up the
classpath and invoke "java" with the right arguments)<br>
<br>
2. Bash or Korn shell<br>
<br>
3. perl or python (as long as I use only vendor-supplied modules,
that is, what comes with RedHat; random stuff from CPAN would
technically require a long approval process from some lawyers).<br>
<br>
4. C<br>
<br>
5. Any other language<br>
<br>
So while C allows the most flexibility in handling the signals that
could come from the children, I/O redirection, etc., it's low on the
list for other reasons. <br><div><div class="h5">
<br>
<br>
Mike Szumlinski wrote:
<blockquote type="cite">
<pre>The way I've always worked around asynchronous calls in shell is by building multiple shell scripts and then firing "monitor" scripts that poll a file in the filesystem with information.
As Clay said, it is far from optimal, but sometimes you only have certain tools to work with so you have to make due.
On Jun 15, 2012, at 6:59 AM, Clay Dowling wrote:
</pre>
<blockquote type="cite">
<pre>On 6/14/2012 6:20 PM, David Lee Lambert wrote:
</pre>
<blockquote type="cite">
<pre>2 quick questions:
1: Is it possible to run a shell function in the background with "&"?
2: What's a good idiom for starting several jobs in the background, then waiting for them all to complete, returning nonzero and printing an error if any of them fail?
</pre>
</blockquote>
<pre>This doesn't sound like a great task for a shell script. A python script or C program, on the other hand, can do this without breaking a sweat if you look up process control in any manual (either the Python book by O'Rielly or "Programming in the Unix Environment").
Clay
_______________________________________________
linux-user mailing list
<a href="mailto:linux-user@egr.msu.edu" target="_blank">linux-user@egr.msu.edu</a>
<a href="http://mailman.egr.msu.edu/mailman/listinfo/linux-user" target="_blank">http://mailman.egr.msu.edu/mailman/listinfo/linux-user</a>
</pre>
</blockquote>
<pre>_______________________________________________
linux-user mailing list
<a href="mailto:linux-user@egr.msu.edu" target="_blank">linux-user@egr.msu.edu</a>
<a href="http://mailman.egr.msu.edu/mailman/listinfo/linux-user" target="_blank">http://mailman.egr.msu.edu/mailman/listinfo/linux-user</a>
</pre>
</blockquote>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888"><pre cols="72">--
David L. Lambert <a href="mailto:davidl@lmert.com" target="_blank"><davidl@lmert.com></a> or <a href="mailto:lamber45@msu.edu" target="_blank"><lamber45@msu.edu></a>
or <a href="mailto:david.lee.lambert@acm.org" target="_blank"><david.lee.lambert@acm.org></a>, formerly <a href="mailto:as4109@wayne.edu" target="_blank">"as4109@wayne.edu"</a>
IM: davidleelambert (Yahoo!) or <a href="mailto:lamber45@cse.msu.edu" target="_blank">lamber45@cse.msu.edu</a> (MSN)
Phone: <a href="tel:616-676-7375" value="+16166767375" target="_blank">616-676-7375</a>
</pre>
</font></span></div>
<br>_______________________________________________<br>
linux-user mailing list<br>
<a href="mailto:linux-user@egr.msu.edu">linux-user@egr.msu.edu</a><br>
<a href="http://mailman.egr.msu.edu/mailman/listinfo/linux-user" target="_blank">http://mailman.egr.msu.edu/mailman/listinfo/linux-user</a><br>
<br></blockquote></div><br>