1

I'm wondering if it matters if I add a crontab to /etc/crontab or crontab -e?

I have an Ubuntu 17 and Debian 9 VM running, and I'm confused which one is the right place.

Thanks in advance!

Клаус Шварц
  • 3,158
  • 28
  • 44
Der.Shorty
  • 21
  • 4

1 Answers1

3

They are not the same.

The crontab command is specific to a user. When you edit your crontab (via crontab -e) you are really saving it to /var/spool/cron/. I find this to be more geared toward interactive setup/maintenance: it uses your $EDITOR. (Though I have seen tools like whenever that will automatically populate a user crontab.

The "system" cron files live in /etc/crontab and /etc/cron.d. These are similar to your user's crontab, but the format has an additional (sixth) field to specify which user to run as, and you'll need root privileges to change these. The latter directory is often used by tools to place a cron script into, by system installs, or your own deployment routines.

You'll also find related system directories in /etc/, such as cron.daily/, cron.hourly/, etc. These hold normal scripts that are run on their respective cadence. E.g., /etc/cron.daily/logrotate rotates system log files daily. They typically orchestrated by your /etc/anacrontab to add some small random delay across systems.

There are a few places to look for documentation of the various pieces of cron. The relevant man pages are:

crontab(1) -- the command
crontab(5) -- spec formatting
cron(8) -- the daemon

An alternative to cron with SystemD now is timers.

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54