[lug] checking bg processes' exit status

Nick Golder nrg at nirgo.net
Mon Mar 10 11:03:44 MDT 2008


On 2008-03-04 11:29 -0700, Jeffrey Haemer wrote:
> Nick,
> 
> The biggest problem is saving $? for each command, especially when you're
> throwing some or all of them into the background, so they run in parallel.
> 
> An easy solution, if practical, is to wrap each process in a shell script
> that saves its exit status.
> Thus
> 

Thanks for the example!  I was trying to do something very similar sans
the extra script.  I was trying to use a function that gets background'd
and uses variable to return an exit code.  It's ends up not being all
that elegant since bash doesn't have a garbage collector - all I end up
doing is polluting the variable space.  I could just go through and
unset all of the variables -or- I could just use your example.  When I
have time I am going to try get this going.  One of the targets is a
read-only filesystem that have nothing that is easily writeable (not my
design)...

> 
> *$ cat foo*
> > #!/bin/bash
> > source ./logging.sh
> > ls $*       # your command goes here
> > *$ cat logging.sh*
> > # save a log, with the error status
> >
> > rm -f $0.[0-9]* $0.out
> > LOG=$0.out
> > exec &>$LOG
> > trap 'mv $LOG ${LOG/out/$?}' EXIT
> > *$ foo; ls*
> > foo
> > foo.0
> > *$ foo bogusfile; ls*
> > foo
> > foo.2
> 
> 
> Hope this helps.
> 
> On Tue, Mar 4, 2008 at 10:26 AM, Nick Golder <nrg at nirgo.net> wrote:
> 
> > I have a bash script that is setting a series of processes in the
> > background and I want to see what their exit codes are.  I have played
> > around trying to find a way to do it and I haven't found a reliable way,
> > yet.  Any suggestions?
> >
> >
> > --
> > Nick Golder
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> > Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> >
> 
> 
> 
> -- 
> Jeffrey Haemer <jeffrey.haemer at gmail.com>
> 720-837-8908 [cell]
> http://goyishekop.blogspot.com

> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug



-- 
Nick Golder



More information about the LUG mailing list