sudo vim crontab vs sudo crontab e - when to use

1.7k views Asked by At

I am trying to get to grip with cron jobs on ubuntu.

I am not sure of the difference between

sudo crontab -e

and

sudo vim /etc/crontab

I assume they both create cron jobs which run under root?

However they give me different files.

sudo vim /etc/crontab

gives me /etc/crontab I think, which is the system wide cron responsible for run-parts and execution of cron.daily etc.

I assume therefore that

sudo crontab -e

creates a personal crontab under /var/spool/cron/crontabs (as per any other user crontab)? But sudo makes it operate under root privileges and associates the crontab to the root user?

Is this correct?

i

1

There are 1 answers

3
hek2mgl On BEST ANSWER

When editing /etc/crontab or creating a file under /etc/cron.d, /etc/cron.daily etc. you are free to choose the user which should run the command. These files should be editable by root only. The file format is:

* * * * * USER COMMAND

When you use the crontab -e command you can't specify the user which runs the command. It is the user which executes crontab -e. The syntax is simply:

* * * * * COMMAND

IMHO it makes no sense to use crontab -e as root. Please check man 1 crontab. It gives a proper explanation.