1

Is it possible to make cron receive it's instructions from the output of a shell script instead of reading a static file?

I'm trying to manage crontabs across a bunch of machines and maintaining separate crontab files for each machine is a chore. I'd like cron to instead run a shell script that prints out crontab lines for each job based on whether a given machine is assigned to that job. Can I do this?

P.S.- I've seen some suggest Puppet/Chef/etc. for this purpose, but I think that's overkill for handling just this one problem.

4 Answers 4

1

I think the easiest way to do this on most distributions would be using automated deployment tools like Puppet/Chef as well as the /etc/cron.d directory. You can place crontabs in that directory, except they use the following format rather than the typical one:

* * * * * <user> <command>

Where is the user that will be running the cron.

You seem to think Puppet is overkill (it's not), but the directory part would apply to any other solution as well.

0

Yes, of course you can do this. Just setup whatever script you need to produce crontab output, and scp it to the target servers.

There, a static cron job can then specifically read those crontabs to execute, from whatever location is convenient.

0

This is exactly the intended use for puppet and friends.

Your only entry in the crontab could be to run the puppet agent, if you don't like how it is setup by the package-management of your distribution.

The external script would be on the puppet-master. In one place. For all machines.

If it is enough of a problem to consider using an external script, I recommend puppet. Chef can surely do something similar.

I started with puppet just to manage the ~/.ssh/authorized_keys on multiple machines, which is a similar "small" problem.

0

A popular trick is to make a crontab entry which updates the whole crontab. This will work fine as long as your shell script never feeds bad data to crontab.

However, I suggest a different approach which will be easier to manage: have a static crontab entry which runs a script frequently. Make the script do all the heavy lifting of figuring out when it's time to run something. This way, you can still use the crontab as a regular crontab without having to make the script know about everything that could be running on every machine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .