rvforumite

Member
Feb 10, 2008
5
0
51
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
 

bhd

Well-Known Member
Sep 20, 2003
149
0
166
JNB ZA
cPanel Access Level
Root Administrator
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/
 

rvforumite

Member
Feb 10, 2008
5
0
51
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?
 

rvforumite

Member
Feb 10, 2008
5
0
51
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.
 

UBERHOST

Well-Known Member
Jan 13, 2008
102
0
66
California, US
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!
 

bhd

Well-Known Member
Sep 20, 2003
149
0
166
JNB ZA
cPanel Access Level
Root Administrator
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
 

rvforumite

Member
Feb 10, 2008
5
0
51
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.