in reply to sequential file handling (again)
Things left to do (other than actually 'finish' the code) is to also make sure your daemon won't chew up all your system resources while doing it's work. For that, I'd suggest making it a 'nice' process using the set_priority() method with a higher value. Also, please be forewarned that I didn't even have the chance to compile the code (actually, I'm in a rush now to do other work.. err.. 'at my real work' ;)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$\;}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sequential file handling (again)
by particle (Vicar) on May 31, 2002 at 21:31 UTC | |
|
Re: Re: sequential file handling (again)
by airblaine (Acolyte) on May 31, 2002 at 21:40 UTC |