Linux – Add Cron Job to Several Servers

cronlinux

What would be the best way to add a new cron job to several servers simultaneously, or to automate the creation of a cron job on several servers.

I am planning on using rysnc to push a bash script out to several servers, but I need to add a cron job that will run this script.

Best Answer

Most modern Linux distributions have support for the /etc/cron.d framework, which would allow a modular approach to pushing cron "snippets" out to multiple servers. This is a special directory that is scanned every minute for available jobs. You can drop small cron files into the directory. It's a more elegant approach than editing a central or per-user crontab.

See: What's the difference between /etc/cron.d and /var/spool/cron? For more information on the slightly-different format needed to use this framework.

I would create the jobs/cron files and scp them to the relevant servers. I think that for something at this scale, Puppet or a full configuration management suite is overkill.