1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Running cron as root

Discussion in 'General Discussion' started by rvforumite, Jun 27, 2008.

  1. rvforumite

    rvforumite New Member

    Joined:
    Feb 10, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    How do I run cron jobs as root? I don't see a cron tab in WHM, although my user account has it in cPanel.

    I've read that some WHM users use ssh to set a cron job. Could someone explain how I do that (I know how to log into ssh and issue commands, but not how to set cron jobs from there).

    A big TIA.

    Tom
     
  2. bhd

    bhd Member

    Joined:
    Sep 20, 2003
    Messages:
    149
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    JNB ZA
    to put the cron into root's crontab:

    Code:
    crontab -e
    You can also manually add a cron file to any of these directories. All depends what you want to do:
    /etc/cron.hourly
    /etc/cron.dailyy
    /etc/cron.weekly
    /etc/cron.monthly
    cron.d/
     
  3. rvforumite

    rvforumite New Member

    Joined:
    Feb 10, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thanks BHD. However, I don't see a crontab in WHM for root, although I see one in my user cPanel (I'm both the host and the user, different IDs and passwords).

    If I wanted to run this script as a user, this is what I'd put into the crontab, substituting the path and the script name:

    15 */1 * * * php -q /path/myscript.php > /dev/null 2>&1

    However, I want/need to run it as root. How would I do this from WHM?
     
  4. rvforumite

    rvforumite New Member

    Joined:
    Feb 10, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Looks like I missed or misunderstood part of what was said in your reply. I went ahead and created a cron file containing the following and uploaded it to /etc/cron.hourly

    # check for xyz every hour
    15 */1 * * * php -q /path/xyzcheck.php > /dev/null 2>&1

    This doesn't seem to run as a cron job, although it works OK if I run it via ssh.
     
  5. UBERHOST

    UBERHOST Member

    Joined:
    Jan 13, 2008
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    California, US
    You would actually do it from the shell, not WHM. This is what bhd was recommending. You could login via SSH, switch to root, and do the following:

    # cp /etc/crontab /etc/crontab.bak
    # nano /etc/crontab


    The nano editor opens up with the file crontab loaded. Move to the bottom of the file and paste the following line:

    15 */1 * * * root php -q /path/myscript.php > /dev/null 2>&1

    Press CTRL+X then press Y to save the file.

    Done!
     
  6. rvforumite

    rvforumite New Member

    Joined:
    Feb 10, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Thank you very much. I'll give that a try.
     
  7. bhd

    bhd Member

    Joined:
    Sep 20, 2003
    Messages:
    149
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    JNB ZA
    Sorry about that. I read your comment
    and just assumed you would know what I meant

    from SSH you would type: crontab -e to edit the cron file for root to do it for a user (if you are root): crontab -e -u username
     
  8. rvforumite

    rvforumite New Member

    Joined:
    Feb 10, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    No need for apology. Although I know how to log in, I rarely do stuff via ssh, so I'm not that familiar/comfortable with it.

    FWIW I downloaded the root crontab file via ftp, added the line I needed, then re-uploaded it. Not the prescribed way to do it, but it seems to work just fine.

    Thanks again for all the help.
     
  9. UBERHOST

    UBERHOST Member

    Joined:
    Jan 13, 2008
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    California, US
    Downloading & editing /etc/crontab via SFTP is just fine. :)
     

Share This Page