Solved

delete files periodically

Posted on 2000-04-28
3
188 Views
Last Modified: 2010-03-05
in one of my perl-cgi script, i create a file with random name when a user submit some information,
now there are more and more files,
i would like to delete some of them.

in my plan, i want to delete files of two days long automatically using a perl program.

can any one provide a script?
0
Comment
Question by:bighuen
3 Comments
 
LVL 3

Accepted Solution

by:
monas earned 20 total points
ID: 2759086
You can do this from [unix] shell

find /directory/with/your/files -type f -mtime +2 -print|xargs rm

this will remove files in subdirectories also.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2760297
find2perl /directory/with/your/files -type f -mtime +2 -exec rm {} \;
#!/usr/local/bin/perl

eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
        if $running_under_some_shell;

require "find.pl";

# Traverse desired filesystems

&find('/directory/with/your/files');

exit;

sub wanted {
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _ &&
    (int(-M _) > 2) &&
    (unlink($_) || warn "$name: $!\n");
}
0
 

Expert Comment

by:mwhuen
ID: 2761838
is it possible to use crontab or sth else that the program works automatically, no need i run the program many times?
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question