简体   繁体   English

“ crontab -e”和“ / etc / crontab”是否相同?

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

I'm wondering if it matters if I add a crontab to /etc/crontab or crontab -e ? 我想知道是否将crontab添加到/etc/crontabcrontab -e是否重要?

I have an Ubuntu 17 and Debian 9 VM running, and I'm confused which one is the right place. 我正在运行Ubuntu 17和Debian 9 VM,但我感到困惑的是哪一个是正确的地方。

Thanks in advance! 提前致谢!

They are not the same. 她们不一样。

The crontab command is specific to a user. crontab命令特定于用户。 When you edit your crontab (via crontab -e ) you are really saving it to /var/spool/cron/ . 当您编辑crontab时(通过crontab -e ),您实际上将其保存到/var/spool/cron/ I find this to be more geared toward interactive setup/maintenance: it uses your $EDITOR . 我发现这更适合交互式设置/维护:它使用您的$EDITOR (Though I have seen tools like whenever that will automatically populate a user crontab. (尽管我见过类似的工具, 只要它们会自动填充用户crontab。

The "system" cron files live in /etc/crontab and /etc/cron.d . “系统” cron文件位于/etc/crontab/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. 这些与用户的crontab相似,但是格式具有一个附加的(第六个)字段来指定以哪个用户身份运行,并且您需要root特权才能更改它们。 The latter directory is often used by tools to place a cron script into, by system installs, or your own deployment routines. 工具通常使用后一个目录将cron脚本放入系统安装或您自己的部署例程中。

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. 您还将在/etc/找到相关的系统目录,例如cron.daily/ cron.hourly/等。这些目录包含以各自节奏运行的普通脚本。 Eg, /etc/cron.daily/logrotate rotates system log files daily. 例如,/ /etc/cron.daily/logrotate每天轮换一次系统日志文件。 They typically orchestrated by your /etc/anacrontab to add some small random delay across systems. 它们通常由您的/etc/anacrontab以在系统之间添加一些小的随机延迟。

There are a few places to look for documentation of the various pieces of cron. 在一些地方可以找到有关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 . 现在,使用SystemD替代cron的是timers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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