Operating System - HP-UX
1832305 Members
2402 Online
110041 Solutions
New Discussion

How to run a cron job with root user

 
SOLVED
Go to solution
Becke
Super Advisor

How to run a cron job with root user

Hi Guys,

On my hp server, i would like to schedule a cron job to be run by root, I'm just wondering whether below is the correct file to modify, so root user can run the job.

/var/spool/cron/crontabs/root.live ?

is root.live file is the one i need to modify, so the root user can run the cron job?

Cheers,
Raf
10 REPLIES 10
Patrick Wallek
Honored Contributor
Solution

Re: How to run a cron job with root user

Nope. What you want to do is a 'crontab -e' from the prompt. That will allow you to modify root's crontab file which is actually /var/spool/cron/crontabs/root
Steven E. Protter
Exalted Contributor

Re: How to run a cron job with root user

As far as I know, that file you refrer to is meaningless. Perhaps some documentation by the sysadmin.

crontab -e edits root cron, though others work on a file and move it to the appropriate location in /var/spool/cron

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
T G Manikandan
Honored Contributor

Re: How to run a cron job with root user

/var/spool/cron/crontabs/root is the file and you should edit and make entries using

#crontab -e
Naveej.K.A
Honored Contributor

Re: How to run a cron job with root user

Hi Rafiq,

Make sure you login as root :) and then do a crontab -e to edit the root's crontab file.

Regards,
Naveej
practice makes a man perfect!!!
Becke
Super Advisor

Re: How to run a cron job with root user

thanks for everyone's response,

I've already trying running crontab -e as root before sending my last message, but it bombed out with an error message that crontab can't be opened?????

cheers
Suraj Singh_1
Trusted Contributor

Re: How to run a cron job with root user

Hi,

Login as root, and look for a file named root in /var/spool/cron/crontabs directory. If the file doesn't exist, create it and make the entries to this file.
Regards,
What we cannot speak about we must pass over in silence.
Y.J.JIN
Advisor

Re: How to run a cron job with root user

Hi,


You can try this.

1. su to root

2. check EDITOR env. (EDITOR=vi)

3. vi /var/adm/cron/cron.allow
Ex. root #<--Add

4. ps -ef|grep cron
Ex. /usr/sbin/cron

5. crontab -e
Ex. * * * * * /var/tmp/test.sh

Hope help you


Devesh Pant_1
Esteemed Contributor

Re: How to run a cron job with root user

Although I am assuming noone has played with the cron.allow and cron.deny files in the /var/adm/cron directory,
please make sure if you have a cron.allow file, the contents have root.
If you don't either have one created with the entries root adm and uucp
If this file is missing for some reason, and you want cron access to the entire system, just touch /var/adm/cron/cron.deny

Also check for the cron daemon
ps -ef| grep cron

if there is none just issue the command

/usr/sbin/cron

I hope after this there is no reason for cron not to work.

thanks
Devesh
Becke
Super Advisor

Re: How to run a cron job with root user

Thanks to all for such a quick response, actually I have found out the problem, the root's cron file was missing in the crontab directory.

I have manually created this file with the touch command and modified it accordingly, i can now run crontab -e or with -l options.

Thanks for everyone's help

Cheers,
Raf
Rory R Hammond
Trusted Contributor

Re: How to run a cron job with root user

Farhan,

I usually do not recommend using crontab -e.

I do:
crontab -l > /var/spool/cron/root.copy

edit the root.copy file.

Then do:
crontab /var/spool/cron/root.copy.

This method gives you a copy and if you finger check a entry, you don't have to recover your crontab entry from backup.

Rory
There are a 100 ways to do things and 97 of them are right