Jump to content

[SOLVED] Cleanup Script Doesn't Execute


papaface

Recommended Posts

Hello,

 

I have a script on my server which is supposed to go through certain directories and delete the files within them if they're more than 1 day old. However the script is not working (i.e nothing is being deleted) and I have no idea why.

 

Does anyone know why this may be happening:

<?php
/*
Cleanup Script
*/
//set_time_limit(900);
error_reporting(1);
ini_set('display_errors',1);
function execInBackground($cmd) {
    if (substr(php_uname(), 0, 7) == "Windows"){
        pclose(popen("start /B ". $cmd, "r"));
    }
    else {
        exec($cmd . " > /dev/null &");
    }
}
function is_empty_dir($dir)
{
    if ($dh = @opendir($dir))
    {
        while ($file = readdir($dh))
        {
            if ($file != '.' && $file != '..') {
                closedir($dh);
                return false;
            }
        }
        closedir($dh);
        return true;
    }
    else return false; // whatever the reason is : no such dir, not a dir, not readable
}
//Do processed
execInBackground('find /home/***/conv/processed -mtime +1 -exec rm {} \;');
execInBackground('find /home/***/conv/uploaded -mtime +1 -exec rm {} \;');
execInBackground('find /home/***/conv/tmp -mtime +1 -exec rm {} \;');
//Do Cache&Stored
execInBackground('find /home/***/public_html/tmpvidstore -mtime +1 -exec rm {} \;');
//Do Logs
execInBackground('find /***/fetchmp3/public_html/convlog -mtime +1 -exec rm {} \;');
//Do Cachefind /home/***/public_html/vidcache/o -mtime +7 -exec rm {} \;
$cachedirs = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','q','y','z');
foreach($cachedirs as $value)
    {
	if(!is_empty_dir('/home/***/public_html/vidcache/'.$value))
        	execInBackground('find /home/***/public_html/vidcache/'.$value.' -mtime +7 -exec rm {} \;');
    }
?>

Link to comment
https://forums.phpfreaks.com/topic/166507-solved-cleanup-script-doesnt-execute/
Share on other sites

Looks like something like this:

#!/bin/bash
find /home/***/conv/processed -mtime +1 -exec rm {} \;
find /home/***/conv/uploaded -mtime +1 -exec rm {} \;
find /home/***/conv/tmp -mtime +1 -exec rm {} \;
find /home/***/public_html/tmpvidstore -mtime +1 -exec rm {} \;
find /***/fetchmp3/public_html/convlog -mtime +1 -exec rm {} \;

for DIR in `echo /home/***/public_html/vidcache/*`
do
find $DIR -mtime +7 -exec rm -rf {} \;
done

 

Would do the same.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.