设置Cron作业以在24小时后删除文件 [英] Setting Cron job to delete file after 24 hours
问题描述
我阅读了所有相关问题,无法理解它们。我正在使用Plesk CPanel按照每个人的建议设置cron作业。
I read all the related questions and was unable to understand them. I am using Plesk CPanel to set cron job as it was advised by everyone.
我想在24小时后从文件夹中删除所有文件。假设我必须每2分钟删除一次(这样我就可以检查其工作与否)。
I want to delete all files from a folder after 24 hours. Assume that I have to delete it after every 2 mins (So I can check its working or not).
我有两个选择:
- 要么运行一个PHP文件,使用cron作业在24小时后删除所有文件
- 使用cron作业命令 rm删除所有文件
我尝试了两种方式,但无法完成任务。
I tried both ways and was unable to get my task completed.
这是cpanel预定任务的图片:
Here is the pic of cpanel scheduled task:
http://i41.tinypic.com/2n0tsfs.png
我要从文件夹 var中删除文件/www/example.com/public/js/complied
。此已完成
文件夹内的所有文件都应删除。我不知道该在Command文本字段中写哪个。
I want to delete files from folder var/www/example.com/public/js/complied
. All files inside this complied
folder should be deleted. I don't know which to write in Command textfield.
我应该使用以下命令吗?
Should I use the following command?
rm /var/www/example.com/public/js/compiled/*.*
还是应该执行php文件?
Or should I execute a php file?
env php -q/var/www/example.com/public/js/cron.php
此Cron.php的源代码为:
The source code of this Cron.php is:
<?php
$dir = "compiled"; // directory name
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..')
continue;
unlink($dir.DIRECTORY_SEPARATOR.$item);
echo "All files deleted";
}
//rmdir($dir);
?>
我已经测试了此代码,它可以正常工作。
I have tested this code and it works fine.
预先感谢。
推荐答案
我在shell脚本中使用了它...
I use this in a shell script...
find /some/path -mtime +7 -exec rm {} \; # delete > 7 days old
这篇关于设置Cron作业以在24小时后删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!