Answers:
尽管@X Tian的答案包含有关crontab的不同文件的信息,但是有关您的问题的基本信息是:
crontab -e
编辑用户的crontab文件(存储在/var/spool/cron/crontabs/
当前Debian系统的目录中,但存储在YMMV中),或创建一个新文件,而不创建一个/etc/crontab
。与crontab -l
(列出crontab文件)和crontab -r
(删除crontab文件)类似。
对于应在用户帐户下执行的所有cron作业,应使用crontab -e
。对于系统作业,应该在下添加一个文件/etc/cron.d
(如果存在);在下面/etc/cron.{hourly|daily|weekly|monthly}
(但不能像包名一样命名!),如果它符合您的目的;或在中添加一行/etc/crontab
。但是请注意,/etc/crontab
系统更新可能会覆盖它。
您真的想阅读手册页man cron
并man crontab
以下摘录涵盖了您的问题。从man cron
注意cron在其假脱机区域(/ var / spool / cron / crontabs)中搜索crontab文件(以/ etc / passwd中的帐户命名);找到的crontab被加载到内存中。请注意,不应直接访问此目录中的crontabs-应该使用crontab命令访问和更新它们。
cron also reads /etc/crontab, which is in a slightly different format (see crontab(5)). Additionally, cron reads the files in /etc/cron.d: it treats the files in /etc/cron.d as in the same way as the /etc/crontab file (they follow the special format of that file, i.e. they include the user field). However, they are independent of /etc/crontab: they do not, for example, inherit environment variable settings from it. The intended purpose of this feature is to allow packages that require finer control of their scheduling than the /etc/cron.{daily,weekly,monthly} directories to add a crontab file to /etc/cron.d. Such files should be named after the package that supplies them. Files must conform to the same naming convention as used by run- parts(8): they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens. If the -l option is specified, then they must conform to the LSB namespace specification, exactly as in the --lsbsysinit option in run-parts.
cron
操作系统之间的差异很大,在某些情况下,您可以在几种实现之间进行选择。
/var/spool/cron/
目录是Linux的专用目录(请参见文件层次结构标准),并且该位置在当前Debian以外的系统上可能有所不同。