Results 1 to 9 of 9

Thread: Running cron as root

  1. #1
    Registered Member
    Join Date
    Feb 2008
    Posts
    5

    Default Running cron as root

    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. #2
    bhd
    bhd is offline
    Registered Member
    Join Date
    Sep 2003
    Location
    JNB ZA
    Posts
    149

    Default

    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. #3
    Registered Member
    Join Date
    Feb 2008
    Posts
    5

    Default

    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. #4
    Registered Member
    Join Date
    Feb 2008
    Posts
    5

    Default

    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. #5
    Registered Member UBERHOST's Avatar
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    102

    Default

    Quote Originally Posted by rvforumite View Post
    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?
    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!

    click logo to visit us for dedicated
    cPanel servers and more

  6. #6
    Registered Member
    Join Date
    Feb 2008
    Posts
    5

    Default

    Thank you very much. I'll give that a try.

  7. #7
    bhd
    bhd is offline
    Registered Member
    Join Date
    Sep 2003
    Location
    JNB ZA
    Posts
    149

    Default

    Quote Originally Posted by rvforumite View Post
    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).
    Sorry about that. I read your comment
    I know how to log into ssh and issue commands
    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. #8
    Registered Member
    Join Date
    Feb 2008
    Posts
    5

    Default

    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. #9
    Registered Member UBERHOST's Avatar
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    102

    Default

    Quote Originally Posted by rvforumite View Post
    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.
    Downloading & editing /etc/crontab via SFTP is just fine.

    click logo to visit us for dedicated
    cPanel servers and more

Similar Threads

  1. Cron <root@xxx> run-parts /etc/cron.hourly
    By mmarch in forum New User Questions
    Replies: 0
    Last Post: 03-31-2009, 11:45 PM
  2. Replies: 2
    Last Post: 07-04-2007, 08:12 AM
  3. cron running twice
    By IRCBrasil in forum cPanel & WHM Discussions
    Replies: 2
    Last Post: 04-04-2007, 01:58 PM
  4. Replies: 12
    Last Post: 08-16-2006, 10:56 PM
  5. Cron <root@server> root run-parts /etc/cron.hourly
    By vishal in forum cPanel & WHM Discussions
    Replies: 5
    Last Post: 11-29-2003, 08:47 AM
bargain