Currently, I am editing my production server’s crons by typing crontab -e.
I would like to store my crontab definitions inside my project, and have my system to load them from there.
Is there any way I can set up the servers existing crontabs to point to an include like this?
IncludeOtherCrontab /path/to/my/project/project.crontab
My system is CentOS release 5.4 (Final)
To do this portably (i.e. not using
/etc/cron.d), assuming your deployment script must coexist with third-party crontab entries and provided your deployment script can execute commands on the target node, not just upload files:test -f project.crontab && { { crontab -u user -l | awk '/^#BEGIN PROJECT SECTION/{hide=1;next}/^#END PROJECT SECTION/{hide=0;next}!hide{print}' ; echo '#BEGIN PROJECT SECTION' ; cat project.crontab ; echo '#END PROJECT SECTION' ; } | crontab -u user - ; }The above verifies that your project-specific crontab section exists, filters it from the given user’s crontab (if it already is there, does nothing otherwise), appends the project section, then reloads the lot.
crontab -u user -adds all the project-specific crontab entries intouser‘s crontab file.