Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
This is what I ended up doing. Thanks for the support. The files in /etc/cron.d/ are like an extension of the cronttab. One thing to be careful of is that you specify a user to run the job. – Curtis_w Nov 6 '12 at 18:44

You can also consider Ansible, it has cron module.

share|improve this answer
I do have to remember to add Ansible to my list of Puppet-alternatives. – Ladadadada Oct 31 '12 at 14:00

Puppet has a cron provider. (probably also CFEngine and Chef and some of the other options)

It also has a neat trick where you can stagger the execution of cron jobs using the hash of the hostname, like this:

cron { "run-myscript":
  command => "/path/to/",
  minute => inline_template("<%= hostname.hash.abs % 60 %>"),

If you have more than a couple of dozen servers or you think you are likely to ever grow to that size, getting started now with configuration management will be worth your while.

For a quick-and-dirty solution, clusterssh might do the trick. A longer term solution to these sorts of problems would be MCollective, Func, Fabric or Capistrano.

share|improve this answer
Without puppet, another quick and dirty solution can be to push files to /etc/cron.d/ (present in most linux distro) using scp and a for loop. But using an scm like puppet is recommended. – user130370 Oct 31 '12 at 13:51

I Would write a script that I would put in a samba share that all my server could access, then I will define a the same cron for each and point to the same script!

share|improve this answer

Should be tried in a proof of concept, but i think it may work with a shared /var/spool/cron directory (such as a nfs share). Did you try it ? I would say it would be the easy way

share|improve this answer
This is a very bad idea, nfs lacks security. Anyone on network would be able to push script that edit /etc/shadow. – user130370 Oct 31 '12 at 16:06
I'm not sure to get your point. The NFS directory, will have quite the same permissions than a local /var/spool/cron folder unless you are making a reference to ACLs ? – Dodger Web Nov 15 '12 at 10:37
nfs was designed in 90's, when security was not a concern. It offer no security at all. You can find many examples on the internet : – user130370 Nov 15 '12 at 12:40

Your Answer


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.