LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2010, 05:16 AM   #1
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Rep: Reputation: 61
Some crontab confusion.


Hi all,

I attempted to run various cron jobs as root - just general server make-tidy stuff. But if I edit the /etc/crontab file directly, these tasks don't get run. However, if I use crontab -e as root, these jobs appear to work. Any idea why this might be the case?

Also, I understand that user cron jobs are stored in /var/spool/cron/<user> (including root). If this is the case, what's the purpose of the /etc/crontab file?

Thanks for any enlightenment
 
Old 06-07-2010, 06:15 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
The /etc/crontab and /var/spool/cron/user files do not have the same format. You should use crontab -e and not worry about the file details. Both /etc/crontab and /var/spool/cron/user files work provided you use the right format for each file and you update the modtime. Crontab -e does everything.
/etc/crontab allow root to execute tasks with user account. /etc/crontab is only writable by root but you can execute scripts with other users in there. This is useful for some system tasks like rotating apache logs or spooling printers where the admin (root) decides that a script should be executed by the user periodically but the user should not be allowed to modify the crontab. /etc/crontab is controlled by root but controls all users whereas /var/spool/cron/user is controlled by each user and can only execute tasks on behalf on the user.
You should use /var/spool/cron/user via crontab -e, and not edit it directly.
 
1 members found this post helpful.
Old 06-07-2010, 06:38 AM   #3
smus
Member
 
Registered: Nov 2005
Location: Turkey
Distribution: Suse
Posts: 104

Rep: Reputation: 16
As a idea pls take a look at the PATH vairable inside your script sometimes it get me crazy and i add use lib './lib','../lib' inside my perl enabled crontab scripts.
 
Old 06-07-2010, 06:41 AM   #4
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by Agrouf View Post
The /etc/crontab and /var/spool/cron/user files do not have the same format. You should use crontab -e and not worry about the file details. Both /etc/crontab and /var/spool/cron/user files work provided you use the right format for each file and you update the modtime. Crontab -e does everything.
/etc/crontab allow root to execute tasks with user account. /etc/crontab is only writable by root but you can execute scripts with other users in there. This is useful for some system tasks like rotating apache logs or spooling printers where the admin (root) decides that a script should be executed by the user periodically but the user should not be allowed to modify the crontab. /etc/crontab is controlled by root but controls all users whereas /var/spool/cron/user is controlled by each user and can only execute tasks on behalf on the user.
You should use /var/spool/cron/user via crontab -e, and not edit it directly.
Yes, but if root can have their own crontab file in /var/spool/cron/root, wouldn't that be the same as /etc/crontab? Seeing as both are only writable as root?

The only difference in format that I see that justifies the existence of /etc/crontab is that the /etc/crontab file can have a user specified after the time to execute and before the command to run.

Still doesn't explain why my /etc/crontab versions didn't work - although perhaps a user to run those commands has to be implicitly specified (which I realise now I didn't do).
 
Old 06-07-2010, 08:14 AM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
Quote:
Originally Posted by arashi256 View Post
Yes, but if root can have their own crontab file in /var/spool/cron/root, wouldn't that be the same as /etc/crontab? Seeing as both are only writable as root?

The only difference in format that I see that justifies the existence of /etc/crontab is that the /etc/crontab file can have a user specified after the time to execute and before the command to run.

Still doesn't explain why my /etc/crontab versions didn't work - although perhaps a user to run those commands has to be implicitly specified (which I realise now I didn't do).
/etc/crontab have a user specified and is only writable by root and that makes a whole world of difference actually. You can deny a user access to crontab and still run jobs periodically with /etc/crontab. It's not useful for root specifically because root is supposed to have all the rights anyway but useful for users like apache or cups. If you would like to run scripts as root, they just use /var/spool/cron/root with crontab -e. This is the best practice. /etc/crontab is seldom use for specific cases where /var/spool/cron/root does not cut it.

Now, if for some reason you really want to use /etc/crontab, make sure you update the modification time of the file (with touch) and if that does not work try to restart your cron job. Make sure you didn't do any error in the file. Any error will make it discarded.

Last edited by Agrouf; 06-07-2010 at 08:17 AM.
 
1 members found this post helpful.
Old 06-07-2010, 08:24 AM   #6
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Original Poster
Rep: Reputation: 61
Okay, many thanks - that makes more sense
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 06:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 08:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 05:03 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 01:35 PM
WM Confusion phoeniXflame Slackware 3 02-16-2003 06:19 AM


All times are GMT -5. The time now is 10:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration