win...">

Perl copy command to wait for copy completion

I am copying the file from windowsLocation1 location to LinuxLocation1 as "windowsLocation1-> windowLocation2-> LinuxLocation1", windowsLocation2 is a swap space accessible from both windows and Linux machine.

copy("//server1/dir1/myfile.txt", "$copy_dir/myfile.txt") or die "Copy failed: $!";
<telnet into Linux machine>
$obj->{telnet}->print( "sleep 10; cp /net/dir1/myfile.txt /tmp/files/");
#added "sleep 10, to avoid the race condition between copy and cp.

      

This "sleep 10" time is sometimes not enough and its throwing error as "cp: read error: I / O error" I think the second "cp" command is trying to access the file when the first "copy" command is all still writes. using Perl v5.6.1

Is there a way to avoid this? thank.

+3


source to share


1 answer


I'm going to assume that you are getting your routine copy

from a module File::Copy

.

After a quick search in CPAN, I came across a module named File::Copy::Vigilant

that seems to suit your needs and successfully test reports from perl 5.6.



I also found File::Copy::Reliable

, but it only has reports up to perl 5.8, although that doesn't prove anything. You might just be a bit of a traveling pioneer as far as module goes ....

+1


source







All Articles