简体   繁体   中英

Are “crontab -e” & “/etc/crontab” the same?

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!

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. Eg, /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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM