Solved

delete files periodically

Posted on 2000-04-28
3
176 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now