Quote:
Originally Posted by ktyson
I wrote a perl script that mounts and unmounts various computers on my network and deletes files in a specific folder if they are older than 60 days. Each computer is mounted in the same folder and I am using Perl module File::Find to traverse the directory and remove the old files. When the different computers have identical directory paths find() works perfect but when the path's are slightly different find() is not using the new directory path. What is going on?
Here is my code
Code:
for my $target (keys(%computer))
{
print "$target\n";
.....mount the computer at /home/mnt/testTool...
......
#DIFFERENT PATHS
if ($target=~/^5.2.2/) {$dir = "/home/mnt/testTool/project"; }
else { $dir = "/home/mnt/testTool/projects"; }
print $dir."\n";
my $reel = "";
my $mtime;
my $age;
my $next = 1;
$reel = $dir. "/Reel";
print $reel."\n";
find(\&processR, $reel);
sub processR {
$mtime = stat($_)->mtime; #modification time
$age = (time-$mtime)/86400; #how many days old the file/folder is
if ($_ =~ /^\d\d\d/ && $age > $days_back)
{
print $reel."\n";
my $file = $reel . '/' . $_;
$cmd =`rm "$file"`;
}
}
Here is the output and clearly the proof of error
5.2.2
/home/mnt/testTool/project
/home/mnt/testTool/project/Reel
/home/mnt/testTool/project/Reel
5.3.2
/home/mnt/testTool/projects
/home/mnt/testTool/projects/Reel
/home/mnt/testTool/project/Reel
rm: cannot remove `/home/mnt/testTool/ project/Reel/495178.txt': No such file or directory
rm: cannot remove `/home/mnt/testTool/project/Reel/498816.txt': No such file or directory
|
Use 'code' tags - see '#' button in "go advanced".
Show the
whole script. If the script doesn't have
Code:
use strict;
use warning;
in the very beginning, first put them and make sure there are no compilation and runtime warnings/errors.
...
It look like you don't have
Code:
use strict;
use warning;
.