[GLLUG] Questions about shell scripting

Mike Szumlinski szumlins at mac.com
Fri Jun 15 10:54:19 EDT 2012


This is actually interesting to me as I work in Perl from time to time, but didn't know it had this functionality.  Go figure, when you self teach you only search for ways you can contemplate to accomplish a task vs. the right way.

-Mike

On Jun 15, 2012, at 10:45 AM, Bryan Laur wrote:

> 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.
> 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)
> 
> foreach $command (@mycommands)
> {
>     if(fork() == 0)
>     { #ischild
>         exec $command;
>     }
> }
> 
> while(wait() != -1)
> {
>     print "return code: " , $? >> 8;
> }
> 
> 
> 
> On Fri, Jun 15, 2012 at 8:09 AM, David Lee Lambert <davidl at lmert.com> wrote:
> Thanks for all the replies.
> 
> 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.
> 
> 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:
> 
> 1.  Java (except then I might need another script to set up the classpath and invoke "java" with the right arguments)
> 
> 2.  Bash or Korn shell
> 
> 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).
> 
> 4.  C
> 
> 5.  Any other language
> 
> 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.  
> 
> 
> Mike Szumlinski wrote:
>> 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:
>> 
>>   
>> 
>>> On 6/14/2012 6:20 PM, David Lee Lambert wrote:
>>>     
>>> 
>>>> 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?
>>>> 
>>>>       
>>>> 
>>> 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
>>> 
>>> linux-user at egr.msu.edu
>>> http://mailman.egr.msu.edu/mailman/listinfo/linux-user
>>> 
>>>     
>>> 
>> _______________________________________________
>> linux-user mailing list
>> 
>> linux-user at egr.msu.edu
>> http://mailman.egr.msu.edu/mailman/listinfo/linux-user
>> 
>>   
>> 
> 
> 
> -- 
> David L. Lambert 
> <davidl at lmert.com> or <lamber45 at msu.edu>
> 
>   or 
> <david.lee.lambert at acm.org>, formerly "as4109 at wayne.edu"
> 
> IM: davidleelambert (Yahoo!) or 
> lamber45 at cse.msu.edu
>  (MSN)
> Phone:  
> 616-676-7375
> 
> _______________________________________________
> linux-user mailing list
> linux-user at egr.msu.edu
> http://mailman.egr.msu.edu/mailman/listinfo/linux-user
> 
> 
> _______________________________________________
> linux-user mailing list
> linux-user at egr.msu.edu
> http://mailman.egr.msu.edu/mailman/listinfo/linux-user



More information about the linux-user mailing list