Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Jan 2010
    Posts
    11

    Default CRONTAB Permission Denied Deleting Files

    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. #2
    Member
    Join Date
    Nov 2011
    Posts
    302
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: CRONTAB Permission Denied Deleting Files

    Please make sure that the script you are using to delete the files through crontab has executable permissions i.e. 755

  3. #3
    Member
    Join Date
    Jan 2010
    Posts
    11

    Default Re: CRONTAB Permission Denied Deleting Files

    Tried that as well. The server is setup as DSO and I am wondering if this has something to do with it.

  4. #4
    Member
    Join Date
    Feb 2006
    Location
    Finland
    Posts
    74
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: CRONTAB Permission Denied Deleting Files

    What is the command line you use to start the script in crontab?

Similar Threads & Tags
Similar threads

  1. How to limit Crontab numbers and permission?
    By allyrice in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 01-07-2010, 05:02 AM
  2. Permission denied on addon-domain files?
    By noimad1 in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 10-14-2006, 12:14 AM
  3. Permission Denied
    By besimtari in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 07-01-2006, 01:49 AM
  4. Overwrite permission denied
    By adapter in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-14-2005, 02:56 PM
  5. Permission Denied!
    By unite the cows in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 09-04-2002, 09:12 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube