Click to See Complete Forum and Search --> : Perl Help


jennAshton
06-03-2003, 04:45 PM
Hi Guys,

I'm not too familar with Perl, so please be gentle with me. I need help on a simple script that extract files from one directory to another.

Basically, I would like to grab new files that are let say 2 min. old from /usr/local/www/somedirectory and scp or rsync to another directory /usr/local/www/somethingelse in the same server.

Thanks ahead. This board is awesome!

Jenn

jeffmott
06-03-2003, 06:20 PM
use File::Copy;

for (qw{file1.ext file2.ext file3.ext etc}) {
copy("/usr/local/www/somedirectory/$_",
"/usr/local/www/somethingelse/$_")
or die "Something went wrong: $!";
}Alternatively, if you don't need to keep the source files after the update, you can use move instead of copy.

jennAshton
06-03-2003, 07:06 PM
Jeff, Thanks for your help. I'll give it a try. How about looking for files that are new let say a file that has been updated 5 min. ago? is it possilbe to pull those new files in your script?

Thanks a ton for replying. You're the best!

Jenn

Charles
06-03-2003, 07:23 PM
#!user/local/bin/perl
use File::Copy;
map{copy ($_, "/usr/local/www/somethingelse/$_")} grep {5 > 60 * 24 * -M $_} </usr/local/www/somedirectory/*.*>;

jennAshton
06-03-2003, 08:03 PM
Wow, Thanks guys! I will def. try it out.

jeffmott
06-03-2003, 11:24 PM
map{copy ($_, "/usr/local/www/somethingelse/$_")}This map should actually probably be changed to a for loop instead. Since map builds a return list that in this case is just being thrown away.copy ($_, "/usr/local/www/somethingelse/$_") for grep {5 > 60 * 24 * -M $_} </usr/local/www/somedirectory/*.*>;

jennAshton
06-06-2003, 06:23 PM
Thanks for helping me out folks.

What if I have a lot of files and directories within my htdocs directory and I ran the script will this affect the processing speed? Can I use File::Compare filehandle to compare the files before copying? So, it will only copy files that has been modified within the last five minute. Blah... I hope I'm making sense. :D

jennAshton
06-09-2003, 05:26 PM
I tried the script and it gave me "No such file or directory" error. the directory was changed /usr/local/www/htdocs1/ and htdocs2. Did I do something wrong?