开发者

Automatically delete files from webserver

I need to delete files from a directory in my web-server and I need some script to do it automatic. And there is few more conditions which need to be fulfilled.

  • It has to clean the directory then total file size exceeds some certain limit for example 1,5GB
  • That files would be deleted every 24 hours.
  • New files like 10 ir 20 mins old would not be deleted
  • It would be just awesome if all of the conditions above wo开发者_如何学Gould be work at the same time.

For deleting files I was thinking of some kind of corn task but I do not know a thing about them so it is tricky for me.

To delete files then a certain limit is reached I was thinking that some kind of PHP script my help. May be there is a library meant for these things.

Any way I will be very happy for any kind of help. May be I just need some fresh thoughts to come up with a right keyword for google ;P

EDIT: My server runs on linux.


If your server is running linux, a cron job is the best option. Simply write a script that checks the conditions you mention (using e.g. stat and some other tools) and deletes the file if they apply, and set crond to run it every 24 hours. Here's a short introduction to cron.

On Windows, you'd do something similar with a script and a scheduled task.


Here is a good cron job tutorial and explanation:

http://www.youtube.com/watch?v=lbJrk55Ae1c

Automate any script to execute. Just write a script that removes all files in folder and that is what you set your cron job to target.

And here is a tutorial about how a PHP programmer can access all files in a folder and use the php unlink() function on each in succession to delete the files. unlink($file);

http://www.developphp.com/view_lesson.php?v=239


Here is an easy way to automatically perform a file deletion depending on the file date : Webmastips : Tips and Tools for webmasters : Automatic File Deletion triggered by a specific date You can customize and automate this task in order to fit your needs. Regards,


Go to your cPanel, select cron jobs and use the following command to create it:

find /home/your_account/public_html/temp/* -mmin +360 -exec rm -r {} \;

It will clean the "temp" (or any other name) file every 360 seconds. You can change that as well.

I am told that if you add the following to the end of the file it will prevent you from getting e-mails every time the cron job executes: /dev/null 2>&1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜