The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CRONTAB Permission Denied Deleting Files

Discussion in 'General Discussion' started by dotcomtim, Jan 1, 2012.

  1. dotcomtim

    dotcomtim Member

    Joined:
    Jan 20, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    I am using crontab to execute a PHP script to delete files and the directory after the files have been deleted. I keep getting permission denied when using the unlink command on the files.

    Here is the PHP Script I am running.
    Code:
    function RemoveDirectory($dirname) {
        if (!file_exists($dirname)) {
            return false;
        }
        if (is_file($dirname) || is_link($dirname)) {
            return unlink($dirname);
        }
        $dir = dir($dirname);
        while (false !== $entry = $dir->read()) {
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            RemoveDirectory($dirname . DIRECTORY_SEPARATOR . $entry);
        }
        $dir->close();
        return rmdir($dirname);
    }
    
    $dirName = 123;
    if (is_dir('/home/xxx/public_html/library/'.$dirName)) {
    	RemoveDirectory('/home/xxx/public_html/library/'.$dirName);
    }
    
    The files are JPG images upload using PHP. The file permissions are 0644 user and group are 99. The directory itself is 777 user and group is 99 as well.

    How do I give access to crontab to run this script and delete the files and directory?

    If I run the script myself directly with the CMS I am using - no problems. Which means there is a permissions issue somewhere that needs to be fixed.

    Any help appreciated. Thanks.
     
  2. storminternet

    storminternet Well-Known Member

    Joined:
    Nov 2, 2011
    Messages:
    462
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Please make sure that the script you are using to delete the files through crontab has executable permissions i.e. 755
     
  3. dotcomtim

    dotcomtim Member

    Joined:
    Jan 20, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Tried that as well. The server is setup as DSO and I am wondering if this has something to do with it.
     
  4. quietFinn

    quietFinn Well-Known Member

    Joined:
    Feb 4, 2006
    Messages:
    998
    Likes Received:
    10
    Trophy Points:
    18
    Location:
    Finland
    cPanel Access Level:
    Root Administrator
    What is the command line you use to start the script in crontab?
     
Loading...

Share This Page