
andrew_b
stranger
Aug 18, 2001, 1:10 PM
Post #1 of 2
(401 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>
|