[Eug-lug] Shell script question

Patrick R. Wade prwade at oip.net
Tue Aug 1 16:34:38 PDT 2006


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.

-- 
On two occasions I have been asked [by members of Parliament!], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able rightly to apprehend the kind of
confusion of ideas that could provoke such a question.
	-- Charles Babbage


More information about the EUGLUG mailing list