Cron job runs with a cPanel user but not the root user

Discussion in 'Apache' started by tyler_durden, Mar 24, 2011.

  1. #1
    The below code when added to a user in a cPanel cron job runs but Permission Denied errors are returned when trying to delete any file older than 5 mn's. This is because the user is not the owner of these files.
    * * * * * /usr/bin/find /home/dir/public_html/mysite.com/cache/* -mmin +5 -exec rm {} \;
    Code (markup):
    However, when I add this same exact line to the crontab file for the root user, I get this error.

    /usr/bin/find: missing argument to `-exec'
    Code (markup):
    Can anyone tell me why it works with a cPanel user but not the root user? I have tried probably 20 different variants and cannot get it to work.
     
    tyler_durden, Mar 24, 2011 IP
  2. koriley

    koriley Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Couple of things to check.

    First you don't need the trailing ";".
    Second make sure that you have a space between {} and \.

    You should probably not be running a cron job like this as root any way. Root should really not be running any cron jobs unless you absolutely need too.

    Who is the owner of the files?

    Kevin
     
    koriley, Mar 24, 2011 IP
  3. koriley

    koriley Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Couple of things to check.

    First you don't need the trailing ";".
    Second make sure that you have a space between {} and \.

    You should probably not be running a cron job like this as root any way. Root should really not be running any cron jobs unless you absolutely need too.

    Who is the owner on the files?

    You could also pipe it to xargs like this
    * * * * * /usr/bin/find /home/dir/public_html/mysite.com/cache/* -mmin +5 | xargs rm -fr

    the r is only needed if you have directories

    Kevin
     
    koriley, Mar 24, 2011 IP
  4. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the suggestions. To answer your questions first, the cache folder is owned by my main user account. The files inside the cache folder are owned by 'nobody' since they are being created by Apache running in mod_php. Up to 10 days ago I knew nothing about Apache, etc. and I have been struggling with how to remove these files at specified times.

    I have tried all the above options and they do not work. I did not see any error messages by removing the ";", but I also removed the "\" since that is only there to escape the ";". Are you saying the "\" should be there when you comment about the space? The space was there beforehand.

    When I use xargs, I get this error. I only used -f
    <code>rm: invalid option --
    Try `rm --help' for more information</code>

    After the cache files are created I don't care who owns them, could I run a script/job that changes them to the same owner as the cache directory?
     
    tyler_durden, Mar 25, 2011 IP
  5. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    After more hours of frustration, I'm leaning towards an issue with my editor. I am currently using nano, should I be using a different one?
     
    tyler_durden, Mar 25, 2011 IP
  6. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok I have spent 10 days on this problem now, and I am completely pissed off at what I have just stumbled upon. I have 60+ cron jobs running perfectly fine with the "mainuser", setting this users cronjobs in the cPanel program.

    When I use "crontab -e -u mainuser" in ssh it pulls up the file using nano. I then Ctrl+O,return to save it to the tmp dir/file, then Ctrl-x which copies it to the proper file and restarts the cron daemon properly. However I have changed NOTHING in that file, only opened it and saved it. Some "mainusers" cronjobs which have been running fine for 3 months crap out now. I have some set for every 6 mn's, and they haven't run for nearly 20 mn's now after the change. What gives??
     
    tyler_durden, Mar 25, 2011 IP
  7. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    oh crapola, all 60+ jobs have not run in over a day. I just haven't noticed it. Editing each line and saving it in the cPanel cronjob tool makes it work again. Not happy...
     
    tyler_durden, Mar 25, 2011 IP
  8. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    And I finally got an error message in an email

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

    No input file specified.
     
    Last edited: Mar 25, 2011
    tyler_durden, Mar 25, 2011 IP
  9. tyler_durden

    tyler_durden Peon

    Messages:
    340
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #9
    And the cron log shows as

    Mar 25 20:57:01 vps crond[3427]: (mainuser) CMD (php /home/mysite/public_html/mysite.com/cron.php^M)

    Notice the ^M at the end of the file name, i notice this symbol is ONLY on the cronjobs that do not work.
     
    tyler_durden, Mar 25, 2011 IP