Gregory Toomey wrote:
> Tom Regner wrote:
>
>> Facco Eloelo wrote:
>>
>
>>> Is there a tool (or just a perl script) which can set four
>>> nameservers(or more) *at the same time* to query?
>>>
> ....
>> foreach (@dnss) {
>> my $res = qx/nslookup -type=A $host $_/;
>> (print $res and exit(0)) if $res;
>> }
>>
>
> The OP wants the results in parallel.
Ah, I overread this part, silly me...
I understood the OP as just to want to avoid the typing...
> This does it sequentially
I know
Than I modify my approach slightly: untested (especialy the use of $_ in the
child-processes seems to be suspicious), but maybe a start; Access to
$store->$result should be governed by a lock or something, but that s to
much to look into right now.
hth,
Tom
------------------------------------------------------
#!/bin/env perl
use warnings;
use strict;
use IPC::ShareLite;
use Storable qw(thaw freeze);
my $store = new IPC::ShareLite( -key => "__dnssearch__",
-create => 'yes',
-destroy => 'no' ) or die $!;
my $results = {};
$store->store(freeze($results));
my @dnss = qw(111.111.111.111
222.222.222.222
111.222.111.222
222.111.222.111);
my $host = $_[0];
my @children = ();
foreach (@dnss) {
my $parent = fork();
if (!$parent) {
my $res = qx/nslookup -type=A $host $_/;
my $store = new IPC::ShareLite( -key => "__dnssearch__",
-create => 'yes',
-destroy => 'no' ) or warn ("Child $_:
". $!);
#
# needs some kind of locking?!?
#
my $results = thaw($store->fetch());
$results->{$_} = $res;
$store->store(freeze($results));
} else {
die "couldn't fork!" unless $parent;
push(@children, $parent);
}
}
while ($#children) {
my $child = wait();
pop @children;
}
$results = thaw($store->fetch());
#
# do something with results
#
------------------------------------------------------
--
Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
http://www.dievision.de