Cron – splitting crontab into several files under FreeBSD

cronfreebsd

Using FreeBSD 9, I would like to know what is the good way to split /etc/crontab into several files.

For example, I would like to put all postfix related jobs in /etc/cron.d/postfix, all logrotate related jobs in /etc/cron.d/logrotate and so on.

Of course, I could use periodic, but it seems that all the jobs would be executed around the same time.

Any idea?

According to man 1 cron, it searches /var/cron/tabs/< usernames> and for /etc/crontab.

Edit 1 : Reasons why I may want to try to do so, as asked in voretaq7's answer.

  • Some company uses poor home-made scm that has no cron plugin nor augeas tool.

  • Writting some scripts that installs some 3rd party software : Appending jobs at the end of /etc/crontab is dirty.

Note that /etc/rc.conf and /usr/local/etc/sudoers already have this feature, therefore I was wondering if there was a "FreeBSD way" to do this for scheduled jobs.

Best Answer

I actually prefer periodic scripts over cronjobs, exactly because periodic executes all scripts sequentially. You can also add more periodic patterns, e.g. put scripts into a directory /etc/periodic/8hourly and add a crontab entry 0 */8 * * * periodic 8hourly to run them.

For subsystems with different user ids you can add user specific crontab files (with crontab -u $user -e, files end up in /var/cron/tabs/$user) -- but IMHO this is less maintainable than one central file.