Click to See Complete Forum and Search --> : Perl Gurus, I Need Help W/ Script


jennAshton
11-10-2003, 04:55 PM
Hi,
I need help with the script below. Bascially, it's a search and replace new files in /www/htdocs/wwwdocs/ to /www/htdocs/docs directory. Well, I would like to know if it's possible for files to be written not only to /www/htdocs/docs/ directory but another server.

So, when someone executes this script it will write to 2 places from /www/htdocs/wwwdocs/ to /www/htdocs/docs/ and another directory on another server that will also replace old files and create new ones if not found.

Please help! Thank you.

#! /usr/bin/perl
use File::Find;
use File::Copy;
use File::Path;


my $top_src = "/www/htdocs/wwwdocs";
my $dest = "/www/htdocs/docs";


find sub {
return unless -f ;

my $more_subdir;
for ( $more_subdir = $File::Find::dir) {
s#^\Q$top_src##;
s#^/##;
}

if (-e "$dest/$more_subdir/$_" and -M "$dest/$more_subdir/$_" <= -M
$_) {
return;
}

mkpath( ["$dest/$more_subdir"], 0, 0775); # $dest must be an absolute
chmod 0775, "$dest/$more_subdir";

copy $_, "$dest/$more_subdir/$_";
chmod 0664, $_, "$dest/$more_subdir/$_";
}, $top_src;

exit;