Permission denied errors when running a script through cron

Discussion in 'PHP' started by tyler_durden, Mar 10, 2011.

  1. #1
    Yet it runs just fine through the browser. The file runs properly on cron, but the permission denied errors are given when the files are trying to be deleted (the script deletes files/folders in a given directory). I even changed all files and folders to 777 and I still get the errors when it runs on a cron job. What am I missing?
     
    tyler_durden, Mar 10, 2011 IP
  2. NLZ13

    NLZ13 Well-Known Member

    Messages:
    166
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    113
    #2
    Full path to file maybe?
     
    NLZ13, Mar 10, 2011 IP
  3. dgreenhouse

    dgreenhouse Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My first thought is that the user the cron job is running as doesn't have permission to create/delete files in the path.
     
    dgreenhouse, Mar 10, 2011 IP
  4. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    dgreenhouse,
    Your theory makes sense as I remember having an issue months back with a cron job running as 'nobody" and having problems. I abandoned that project and never resolved it. How do I have the cron job run as a different user?
     
    tyler_durden, Mar 10, 2011 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    The easy way is to login as that user via SSH and edit that user's crontab.

    crontab -e
    Code (markup):
    Or, if you're a superuser.

    crontab -u username -e
    Code (markup):
     
    joebert, Mar 10, 2011 IP
  6. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Eeks, I have only used CPanel and WHM so far, is there someway using that or do I have to use SSH? Looks like I may need to read up a bit on this.
     
    tyler_durden, Mar 10, 2011 IP
  7. dgreenhouse

    dgreenhouse Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It's always wise to have SSH; if it's available...

    Makes life easier for these types of issues.

    Also, you can discuss it with the tech support dept. of your hosting company. They may very well have a solution for you.
     
    dgreenhouse, Mar 10, 2011 IP
  8. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm assuming I have superadmin rights as this is a VPS I have recently purchased, and I am sure learning a whole lot which I didn't need to know before. I'm assuming the "root" user is the superadmin?

    If so, how would I create a new user to run this cron job as I probably don't want to change the config for "nobody" for security reasons. I have remoted into SSH before so i will attempt this.
     
    tyler_durden, Mar 11, 2011 IP
  9. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #9
    you have to try it as root ... root is the superadmin with ALL PERMISSIONS ON SERVER! Use it wisely!
     
    G3n3s!s, Mar 11, 2011 IP
  10. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #10
    ok, I feel stupid but I need more help. I am using SSH through Parallels Power Panel and I can do the command "crontab -e" and it lists the running crontabs, BUT I don't know how to add a new one. After the listing, my cursor is right on top of the first line. Is there simple commands I am missing, or should I use a different SSH program?
     
    tyler_durden, Mar 16, 2011 IP
  11. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Now I see, crontab is a file and the -e is to edit it. Now I have to figure out how to save the edit.
     
    tyler_durden, Mar 16, 2011 IP
  12. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #12
    If the editor is 'ed', then 'w' will write your file to be saved.
     
    drhowarddrfine, Mar 16, 2011 IP
  13. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Ok I am a lot closer now, I have had some time to learn the shell commands. But now I have this issue, and I think it may be a directory issue between root and other users.

    * * * * * /usr/bin/php /home/sites/public_html/mysite.com/file.php

    This above line works for a user when setup in cpanel/cron program, but NOT with the root crontab file edited. It's the same exact line, yet the messages I am getting are 404 errors. Does the root directory have a different file structure than other users?
     
    tyler_durden, Mar 18, 2011 IP
  14. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I should make it clearer that the email messages I receive on the cronrun when using the root crontab are:

    Status: 404 Not Found
    X-Powered-By: PHP/5.2.16
    Content-type: text/html

    No input file specified.


    It works just fine when added to another users cron, but that is also using Cpanel to edit it.
     
    tyler_durden, Mar 18, 2011 IP
  15. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I'm about ready to throw my laptop as far as I can... I have been messing with this for over a week now.

    What is the difference between "/usr/bin/php" and "/usr/bin/php -q" ??
     
    tyler_durden, Mar 18, 2011 IP
  16. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #16
    ok, I am going to start a new thread with this issue, but I think I found the problem. These files/folders trying to be deleted are created by Apache with the user of "nobody".
     
    tyler_durden, Mar 19, 2011 IP