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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.