use strict; use File::Find; # plug your own value here $rotate_dir = '/share/files/rotate'; $move_timeout = 5*60; # 5 minutes. my %files; while (1) { # find files that have to be rotated my @rotate; find(\&wanted, $rotate_dir); rotate(); } sub wanted { if (exists $files{$File::File::name}) { # alright, we saw it before.. so, has it's # time come to move? push @rotate, $File::File::name if ($files{$File::File::name} < time - $move_timeout); } $files{$File::File::name} = time; } sub rotate { # "I know, I don't have to use global vars, I KNOW!" ;) for (@rotate) { my $new_path; if (m|/main/|) { # initial spot $new_path = $_; # drop it to the first sale rep's directory $new_path =~ s|/main/|/dir_1/|; } else { # retrieve sales person's id my ($sales_id) = ($_ =~ m|(\d+)/$|); my $new_id = $sales_id + 1; $new_dir =~ s|$sales_id/|$new_id/|; # drop to main directory if next sale's rep # id isn't valid (exists) $new_dir = 'dir/main' unless (-d $new_dir); } # move to that new directory... } #### $"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+)-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print"- $1"}&&`rm $1`; print$\;}