Re: fork,exec, and parallel processing



On 26 Mar 2007 08:29:28 -0700, "drew@xxxxxxxxxxx" <drew@xxxxxxxxxxx>
wrote:

Hi,

I've a need for a script that can query multiple NetBackup servers for
a clientlist, in parallel (rather than sequentially) if possible.

I've developed the following code, which seems to work, but also seems
to only run sequentially. What can I do to correct the script so it
will run the children in parallel?

Thanks,

Drew

__BEGIN_SCRIPT__
use strict;

my $passes = 0;
my @kids = ();
my @clients;
my %backup_results = ();
my @serverlist = qw/server1 server2/;
my %client_to_master = ();

for my $server (@serverlist) {
my $pid = open(KID_TO_READ,"-|");
print "PID: $pid\n";
if ($pid) {
# parent
@clients = ();
while(<KID_TO_READ>) {
next if (/Windows/);
next if (/^Hardware /);
next if (/^-----/);
my ($hardware,$os,$client_name) = split;
push(@clients,$client_name);
$client_to_master{$client_name} = $server;
}
close(KID_TO_READ) or warn "Child exited: $?\n";
$backup_results{$server}{'clientlist'} = [@clients];
push(@kids, $pid);
} elsif ($pid == 0) {
# child
my @options = qw/ssh/;
my $path = '/usr/openv/netbackup/bin/admincmd';
my $cmd = 'bpplclients';
my $bpplclients = $path . '/' . $cmd;
push(@options,$server,$bpplclients);
exec('/usr/bin/sudo',@options) or die "Can't exec: $!
\n";
exit(0);
} else {
die "Can't fork: $!\n";
}
}


foreach(@kids) {
waitpid($_,0);
}

exit(0);

__END_SCRIPT__

Use:
http://search.cpan.org/~dlux/Parallel-ForkManager-0.7.5/ForkManager.pm

However you cannot write to a file or array while this is forking due
to overwrites..

Dump the data you need into a Database then parse the database once
the script is finished...

Works like a champ...

Joe

.



Relevant Pages

  • Re: login scripting
    ... DC Servers are Windows 2003 Server. ... Clients are Win 2000 Pro, and a few Win XP clients. ... I observe the minimized login script on the task bar, ... already starting to process startup group items. ...
    (microsoft.public.win2000.general)
  • Re: fork,exec, and parallel processing
    ... I've a need for a script that can query multiple NetBackup servers for ... What can I do to correct the script so it ... my @clients; ... ## harvesting code from above here, ...
    (comp.lang.perl.misc)
  • Re: I cant logon to the Domain from any Win NT 4.0
    ... reason is that you have no WINS server or the machines ... are not "clients" of that WINS database (a single WINS ... "Servers don't need to resolve names" or "Win2000 doesn't ...
    (microsoft.public.win2000.active_directory)
  • Re: create database: programmatically vs app-tools
    ... > servers if the database is created in script. ... > Mark wrote: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: running shell scripts from Filemaker Pro SERVER
    ... upgrade the clients is helpful at least, but that, i agree, is pretty ... and that person runs the script manually. ... logged in a utility table in the database. ... eventually the machine that actually does the updates will process it. ...
    (comp.databases.filemaker)