Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
Thank you very much. I'll give it a try as soon as I can. –  Eric DANNIELOU Aug 9 '12 at 11:24
    
Adding more periodic patterns was really the solution I was looking for : Packs of jobs can be split at will and scheduled with different frequency. –  Eric DANNIELOU Aug 14 '12 at 22:38
add comment

FreeBSD's cron is a traditional Vixie cron -- It doesn't support what you're asking for.

Quite frankly I can't see why you would want it: Why would you want to scatter your crontab into a bunch of files, where you can't get a clear picture of what is running when?
I've always found the traditional crontab ordered by periodicity/frequency (hourly,daily, weekly, monthly, yearly) very easy to read, and easy to wrap one's head around when adding new stuff to the schedule.

If you want to break your crontab out by functional unit you can do that too - Just create blocks separated by whitespace and comments.


If this is not enough for your use case and you really want the Linux-style cron structure with a cron.d directory and sub-files you can have it: Just install anacron from the ports tree (sysutils/anacron) and configure it as you like.

Make sure to document what you've done -- I've encountered a lot of FreeBSD systems in my career, and I've never encountered one not running the standard Vixie cron. If you create an environment that is an exception to the usual way of doing things you'll want everyone to know why you changed it, and how they should deal with the systems.

share|improve this answer
    
Thanks for the anacron workaround, didn't think of this one. –  Eric DANNIELOU Aug 7 '12 at 11:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.