Operating System - Linux
1829458 Members
2251 Online
109992 Solutions
New Discussion

Difference between /etc/crontab and crontab -e

 
SOLVED
Go to solution
Stefan Saliba
Trusted Contributor

Difference between /etc/crontab and crontab -e

What is the difference between adding cron jobs in /etc/crontab or adding using crontab -e which creates a files in /var/spool/cron in Linux.

Stefan

4 REPLIES 4
U.SivaKumar_2
Honored Contributor
Solution

Re: Difference between /etc/crontab and crontab -e

Hi,
you can say editing /etc/crontab will make cron
configuration static or permanent. cron daemon
will first look at this file for jobs.
But doing crontab -e will edit current crontab
file and is dynamic.

You will also find files that control cron's actions in the /var directory. Remember that /var is where varying data get stored. The spooler for cron is located here. The cron spool contains the queue of work to be done and is occupied while the computer is doing or preparing to do the work. Once the job is finished, the cron spooler is emptied and waits for the next scheduled job to be placed in the spooler.

regards,
U.SivaKumar


Innovations are made when conventions are broken
Rory R Hammond
Trusted Contributor

Re: Difference between /etc/crontab and crontab -e

I prefer keeping a static copy of my crontab entries. I edit the copy and then execute
crontab copy_file.


The reasons I do this:
1. I have fat finger'd editing and had to recover lost entries.
2. I have junior admins. that make "improvements". I can compare the current entries with my static/master. Which I can decide to update or delete the changes.
3. I have a backup resource to easily recover lost cron entries.

Rory
There are a 100 ways to do things and 97 of them are right
Ted Ellis_2
Honored Contributor

Re: Difference between /etc/crontab and crontab -e

if you are still reading this...

run crontab -l > /tmp/... this will copy the exising crontab to a file.

now make a copy of this file and name it something similar with a new on it...

now edit that last copy with vi...

run crontab to load the new crontab. Now you have an old copy of the crontab incase something goes bad.... this has saved me some headaches in the past
Stuart Browne
Honored Contributor

Re: Difference between /etc/crontab and crontab -e

"/etc/crontab" is used for 'System Crontabs'. This would usually be used for system mainteance (rotating logs etc.) and thus has the ability to specify which user a given task runs as (6th field). It has a user basic environment.

Any changes to this file are read dynamically (I beleive it's done based on the last modification time of the file).

"crotnab -e" is used for 'User crontabs'. Any user can add jobs to their own crontab. This will get executed as that user with a basic environment.

User crontab's *MUST BE MODIFIED* using the 'crontab' utility. Modifying the /var/spool/cron/* files directly can cause unexpected results (to say the least).

Using 'crontab -e' edits the jobs in place. 'crotnab -l' will list for the current user. 'crontab some.file' will re-write the current crontab for the current user with the tabs listed in 'some.file'.

'crontab -u ' allows you to modify user-crontabs for other users (as root).
One long-haired git at your service...