[Eug-lug] Shell script question

larry price laprice at gmail.com
Tue Aug 1 16:52:09 PDT 2006


On 8/1/06, Patrick R. Wade <prwade at oip.net> wrote:
> A shell script runs a for loop iterating a command:
>
> #!/bin/sh
> # foo.sh ; an example script
>
> for i in foo bar baz
>         do find /home/$i
>         done
>
> exit 0
>
> If we run this and observe top, we will see three processes; one for
> foo.sh, another for a child foo.sh (the for loop) and one for find.
>
> If i send a kill to the parent foo.sh process, the child foo.sh and find
> jobs will continue running.  This, from what i gather, is normal *NIX
> behavior.  My objective, however, is to ensure that foo.sh exits by a
> certain time, so i have an at job waiting to send it a kill.  Is there
> an idiom when writing the script to ensure that the kill it receives
> will kill the child processes as well?  Is there a completely different
> approach i need to take when the design requirement of termination by a
> time certain is added?  Exhortations to learn Python are perhaps apropos
> but useless in the short term.

are you on a machine that supports pkill ?

python is wonderful but shell scripts are sometimes simpler.


More information about the EUGLUG mailing list