Cron – Including file into crontab config

cron

I'm trying to put project specific crontab config into code repository to make it easy to update cron jobs on all backends when deploying.

Is it possible to include files into crontab config? Something like

* * * * * execsomething /blablabla/blah/
* * * * * onemore /blablabla
@include '/home/user/project/crontab.conf'

Best Answer

Depending on your cron daemon and your distribution, there should be several directories in /etc where you can put files with jobs for cron.

Scripts (not cron-formatted jobs) placed in the following directories will be executed at the specified intervals. Note that frequency is guaranteed but the exact time it runs may not be. For most users these directories are sufficient:

/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly

cron-formatted jobs (like your examples above) placed in the following directory will be executed by cron at the specified times. Note that in addition to the normal entries the user of the job needs to be specified as well, before the command. For packages and software distributions this method is the best way to distribute cronjobs:

/etc/cron.d

Example of a cron.d formatted command:

1 1 * * * root echo "serverfault is awesome" > /dev/null
Related Topic