[SLL] multi-threading

Robert Woodcock rcw at blarg.net
Mon Sep 29 08:33:06 PDT 2008


On Mon, Sep 29, 2008 at 03:42:53AM -0700, Paul A. Franz, P.E. wrote:
> If you see something in the script that you think is poor practice, don't hesitate to
> point it out.

For reversing an IP address, try this:

sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\4.\3.\2.\1/'

It'll have to spawn a few dozen less processes each time. :)

Also, for padding a variable when printing it, try the shell printf command:

printf "%15s" $foo

Also, in my scripts I've switched to using $(foo) instead of `foo` - it's
clearer and it's nestable.

let is a bashism, BTW. Make sure you put #!/bin/bash at the start of your
script. If you want it to be portable you can use "n=$(expr $n + 1)".

> I wonder if I could get clever using your scheme with "select"? Here's how
> it is described in the bash manual.

It looks like it's designed for asking the user questions (not for
non-blocking IO like the select system call). While you could certainly feed
it stuff via a pipeline, I don't see why (maybe I'm not being clever :)

> > A batch of 6, then another batch of 6, would be suboptimal because you'd
> > often end up with a single straggler process that has to finish before the
> > next batch gets kicked off.
> 
> Retaining order is going to take some cleverness. I can't think of any way to do it
> other than filling a 2 dimensional array, rather than printing the results
> sequentially as I do now.

Or print a number on each line along with the results so you can sort by
that number and then discard it (presumably you'd be dumping the output to
temp files and then displaying them).

Since I'm just reading this this morning before I head off to work, I
haven't had time to get the two scripts meshed together. I'll write again
once I've had time.

One other thing - the dig command has an -f option for reading in a bunch of
queries via a file. I don't think it parallelizes.

Also, I used an httpd log analyzer (analog) at a previous job which batched
DNS lookups and maintained a cache file for them. Along those lines, apache
comes with a logresolve utility which might be usable, and there's some
offshoots of that such as logresolve.pl
(http://www.linux.org/apps/AppId_1351.html).
-- 
Robert Woodcock - rcw at blarg.net
"We would like to return to work with our writers. If we cannot, we would
like to express our ambivalence, but without our writers we are unable to
express something as nuanced as ambivalence."
	-- Jon Stewart and Stephen Colbert


More information about the linux-list mailing list