cron文件有一个很好的布局约定吗?

我目前面临一个cron文件,其中包含十几个不同的应用程序的任务 – 一些只有一个,一些有很多。 我试图找出组织和logging这些过程的好方法。 有没有什么公约可以模仿,还是我坚持做出来的?

#minute hour mday month wday who command ## Acme Anvil Application # clear logs every 5 minutes */5 * * * * root /path/to/clear_logs # monthly maintenance 30 5 1 * * root /path/to/acme/maintenance ## Fabricam # adjust timing */30 0-5 * * * fab /path/to/bin/fab_time ## Etc... 

如果您的系统支持/etc/cron.d,您也可以尝试将cron作业分解为单个文件,并按应用程序进行分组。

 root@linuxbox:/etc/cron.d# ls sa-update sysstat vnstat 

请注意,/etc/cron.d中cron作业的格式稍有不同,因为您可以将用户在时间字段和命令本身之间运行命令,例如,

 root@linuxbox:/etc/cron.d# cat sa-update ### OPTIONAL: Spamassassin Rules Updates ### # # http://wiki.apache.org/spamassassin/RuleUpdates # Highly recommended that you read the documentation before using this. # ENABLE UPDATES AT YOUR OWN RISK. # # /var/log/sa-update.log contains a history log of sa-update runs 10 4 * * * root /usr/share/spamassassin/sa-update.cron 2>&1 | tee -a /var/log/sa-update.log 

我会build议确保在/ etc / crontab文件的最后注释。 如果没有以换行符结束,cron的许多实现将不会触发文件中的最后一个作业。

Debian Lenny就是其中之一。