Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Fork multi processes

by saurya1979 (Initiate)
on May 04, 2012 at 08:29 UTC ( [id://968887]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Fork multi processes
in thread Fork multi processes

In my case, there is just 1 source and 1 destination server for rsync. I want to rsync directories located at different place on source server to the destination server. So I wanted to run multiple rsyncs to make it faster.

Replies are listed 'Best First'.
Re^4: Fork multi processes
by salva (Canon) on May 04, 2012 at 15:27 UTC
    #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH::Parallel 0.12; use Net::OpenSSH::Parallel::Constants qw(OSSH_ON_ERROR_IGNORE); @ARGV == 3 or die <<EOU; Usage: $0 host src_dir dst_dir EOU my ($host, $src, $dst) = @ARGV; opendir my $dh, $src or die "unable to open $src"; my @ls = grep !/^\.{1,2}$/, readdir $dh; close $dh; my %now; sub on_error { my ($pssh, $label, $error) = @_; warn "transfer of $now{$label} by $label failed\n"; OSSH_ON_ERROR_IGNORE; } sub fetch_next { my ($pssh, $label) = @_; if (@ls) { my $file = shift @ls; $now{$label} = $file; warn "$label is copying $file\n"; $pssh->push($label, rsync_put => "$src/$file", "$dst/$file"); $pssh->push($label, sub => \&fetch_next); } } my $p = Net::OpenSSH::Parallel->new(on_error => \&on_error); $p->add_host("worker$_", $host) for 1..5; $p->all(sub => \&fetch_next); $p->run;
    Requires Net::OpenSSH::Parallel 0.12 I have just uploaded to CPAN.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://968887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found