CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Trouble moving files with File::Copy module

 



andrew_b
stranger

Aug 18, 2001, 1:10 PM

Post #1 of 2 (584 views)
Trouble moving files with File::Copy module Can't Post

I'm writing a script that will move logfiles to an archive directory after being rotated by a log analysis program. The script seems to find the files which match my criteria, and will even print a list of them. But when I try to use move() from the FILE::COPY module, the script dies and says:
"Move failed: No such file or directory at movelogs.pl line 28."
The syntax for the move() seems to be correct as per my perl books. Any help?

<code>
#!/usr/local/bin/perl

#move/archive rotated logfiles
#my log analysis program renames logfiles logfile_name.yyyymmdd
#these files need to be moved to an archive directory, tar'd and gzip'd

use File::Copy;

#define variable for date/stamp in yyyymmdd format:
($day, $month, $year) = (localtime) [3,4,5];
$yyyymmdd = sprintf ("ddd", $year+1900, $month+1, $day);


#define directories to be searched for rotated logfiles
@logdir = "/usr/home/juanbro/usr/local/etc/httpd/logs/";

#for each directory specified, open that directory and read in the files there
foreach $logdir (@logdir) {
opendir(DIR, $logdir) or die "Can't open $logdir: $!";
while (defined($file = readdir(DIR))) {
#does the file contain todays datestamp?
if ($file =~ /$yyyymmdd/) {
#move file
move("$file", "/archive/$file") or die "Aarrghh! Move failed: $!";
# print "found a match: $file \n";

}
}
closedir (DIR);
}
</code>



andrew_b
stranger

Aug 19, 2001, 9:04 AM

Post #2 of 2 (573 views)
Re: Trouble moving files with File::Copy module [In reply to] Can't Post

Never mind. It was a path problem (duh).


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives