From: Sivaram Neelakantan on
I plot a lot of graphs in my shell script and I'd like to run it as a
background job. This is what I have currently

gnuplot < $GPLOTDIR/${amc}/${FILENAME}_${PERIOD}.gplot

within a loop.

If I plug in a & at the end, presumably it goes as a background job.
How do I ensure that the shell script waits for all the bg jobs to get
over before exiting? Or is that something I should not worry about?

sivaram
--
From: Ed Morton on
Sivaram Neelakantan wrote:
> I plot a lot of graphs in my shell script and I'd like to run it as a
> background job. This is what I have currently
>
> gnuplot < $GPLOTDIR/${amc}/${FILENAME}_${PERIOD}.gplot
>
> within a loop.

OK, but quote your variables unless you have a specific reason not to.

> If I plug in a & at the end, presumably it goes as a background job.

Right

> How do I ensure that the shell script waits for all the bg jobs to get
> over before exiting?

man wait

> Or is that something I should not worry about?

Only if you have something you want to do once they all complete, e.g.
collect and aggregate their output or print a "done" message or...

Ed.
From: Kevin Collins on
On 2009-10-19, Ed Morton <mortonspam(a)gmail.com> wrote:
> Sivaram Neelakantan wrote:
>> I plot a lot of graphs in my shell script and I'd like to run it as a
>> background job. This is what I have currently
>>
>> gnuplot < $GPLOTDIR/${amc}/${FILENAME}_${PERIOD}.gplot
>>
>> within a loop.
>
> OK, but quote your variables unless you have a specific reason not to.

Why? Just curious, but I don't see a reason to quote variables in this case...
They will be interpolated either way.

[snip]

Thanks,

Kevin
From: Barry Margolin on
In article <slrnhdpppc.qgi.spamtotrash(a)vai.unix-guy.com>,
Kevin Collins <spamtotrash(a)toomuchfiction.com> wrote:

> On 2009-10-19, Ed Morton <mortonspam(a)gmail.com> wrote:
> > Sivaram Neelakantan wrote:
> >> I plot a lot of graphs in my shell script and I'd like to run it as a
> >> background job. This is what I have currently
> >>
> >> gnuplot < $GPLOTDIR/${amc}/${FILENAME}_${PERIOD}.gplot
> >>
> >> within a loop.
> >
> > OK, but quote your variables unless you have a specific reason not to.
>
> Why? Just curious, but I don't see a reason to quote variables in this case...
> They will be interpolated either way.

Why write your script in such a way that it will fail if $GPLOTDIR,
$amc, $FILENAME, or $PERIOD contains whitespace, when it's so easy to
avoid this problem?

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Arcege on
On Oct 19, 1:47 pm, Sivaram Neelakantan <nsivaram....(a)gmail.com>
wrote:
> I plot a lot of graphs in my shell script and I'd like to run it as a
> background job.  This is what I have currently
>
> gnuplot < $GPLOTDIR/${amc}/${FILENAME}_${PERIOD}.gplot
>
> within a loop.
>
> If I plug in a & at the end, presumably it goes as a background job.
> How do I ensure that the shell script waits for all the bg jobs to get
> over before exiting?  Or is that something I should not worry about?
>
>  sivaram
>  --

Yes, if you add a "&" at the end, it will go to the background. But
not as a job. Job control is available on interactive shells. You
can wait for all pipelines (background processes) that have been
placed in the background with the 'wait' command.
# call each in the background
for file in dir/*; do
program $file &
done
# now wait for them all
wait

However, it may not be the most efficient use of the disk to have too
many of them running at once.

-Arcege