1821051 Members
2467 Online
109631 Solutions
New Discussion юеВ

Re: cron

 
Michael_33
Regular Advisor

cron

Hi all,

I have some questions:

1. Who is the best guy to stop/start cron process. root or anyone?

2. the owner of all cron job files must be root? and the right should be 400?

3. When I modified a cron job, what is the
best way to let it refresh? just do crontab file? sometimes it seems doesn't work.

Thanks
10 REPLIES 10
Scott Van Kalken
Esteemed Contributor

Re: cron

Michael,

generally cron is "owned" by root. That is the cron process:

root 1406 1 0 Nov 7 ? 0:00 /usr/sbin/cron

This just makes sure that things get run.

To start and stop on an HPUX system the easiest way is:

/sbin/init.d/cron stop
/sbin/init.d/cron start

Leave it running all the time.


To refresh cron, you need only edit the crontab.

crontab -e

this will take you into a vi editor mode (by default unless your VISUAL variable is set to something else). I'm lazy, so hitting and quits this.

Generally anyone can use cron.

You may however have two files called cron.allow and cron.deny OR at.allow and at.deny.

These (if imnplemented) can allow and deny specific users from using cron. It's generally a good idea unless you want your users to be putting in huge cron jobs all the time.

man cron should be a start as well.

Marco Paganini
Respected Contributor

Re: cron

Hello Michael,

Cron normally runs as root, meaning that only root can stop/start the cron daemon.

Normally, you should not mess directly with cron's spool files. If you want to submit a job to cron, use:

crontab -e

This will open an editor window with the current contents of your crontab.

To see what's on your crontab:

crontab -l

Individual users can have individual crontabs. Cron will run each user's cron jobs as that user's uid.

Regards,
Paga
Keeping alive, until I die.
Michael_33
Regular Advisor

Re: cron

Thanks for the reply, so you mean I can just
vi the file and no need to stop/start cron?

Scott Van Kalken
Esteemed Contributor

Re: cron

No

Don't just vi the file.

Switch to root - or whoever and use crontab -e

This is the correct way update cron.

What happens when you do this is that cron will automagically schedule a re-read of the file if it is changed.

This is how cron will know that new stuff is there.

If you edit the file directly, then cron may get confused.
Michael_33
Regular Advisor

Re: cron

thanks, as you said I login as root, and
do crontab -e, it will only change the
root's cron file, if I want to moify
other users, such as abc, how can I
do that? when I login as abc, and do
a crontab -e, it will go into /var/tmp/????
not the right file, btw abc already have
a cron file.
Deepak Extross
Honored Contributor

Re: cron

Any user who is 'allowed' to use cron can submit/edit his jobs to cron using crontab -e.
So yes, you can just su to the user's id and do a crontab -e; it will work.
You can verify by doing a crontab -l after making the changes.
Varghese Mathew
Trusted Contributor

Re: cron

Hi,
The best way to do that is login as your user "abc" and do the same way how you have done it for root. Remember you may need to have the proper file permissions for that user as well.

Thats it.
Cheers !!!
Mathew
Cheers !!!
Scott Van Kalken
Esteemed Contributor

Re: cron

you just su to user abc

then do a crontab -e from there
Michael Tully
Honored Contributor

Re: cron

Hi,

To change a different users crontab
you need to do this.

# su - abc
$ crontab -l >/tmp/wrkfile
$ vi wrkfile
(make changes and save)
$ crontab /tmp/wrkfile
$ exit
#
It is not a good idea to directly edit
the crontab file. It is better to edit
a copy and re-submit it.

-Michael


Anyone for a Mutiny ?
Darrell Allen
Honored Contributor

Re: cron

Hi Michael,

As others have said, you should not directly edit files in /var/spool/cron/crontabs. You can use either "crontab -e" or "crontab -l >file;edit file;crontab file". Either way, you must "su -" to the account for which you want to modify the crontab.

I suggest you make a backup of the account's crontab file before you change it (but don't make that backup in /var/spool/cron/crontabs). I like to make a directory specifically for crontab backups so I do:
cd /var/spool/cron
mkdir crontabs.bak
cp -p crontabs/* crontabs.bak

That way I have a backup of all the crontabs. Of course, non-superuser accounts would have to make their copy somewhere else but I'm assuming you are talking about the ones you (the superuser) change.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)