Multi computer cron

I have many computers and I ssh between them.

I have a single cron file, which I manually type after into each computer.
And when I change this cron file, I have to manually ssh into each computer to update its cron accordingly.

Is there any way to have each computers cron, become a function of this file?

That way I could just have a single file, which gets synced between the computers and thus, updating the cron in each.

Asked By: john-jones


This answer is assuming that you are concerned with the crontab of a particular user, myuser.

A cron job re-reading the cron schedules from a file (crontab crontab.txt) would be fairly easy to set up, but you could do that from ssh directly with

ssh myuser@remote crontab - <crontab.txt

where crontab.txt is stored locally.

This could be put into a loop:


remotes=( remote1 remote2 remote3 )

for remote in "${remotes[@]}"
    ssh "myuser@$remote" crontab - <crontab.txt

The alternative way that I initially skipped over above, with a job that re-reads the crontab:

This would require a crontab with at least a job like this:

0 * * * * crontab "$HOME/crontab.txt"

This job re-reads the schedules from crontab.txt in your home directory on the hour every hour. That file should always contain at least this job. You may then add other jobs to the file (by syncing the file from elsewhere), which would be added to the user’s active crontab on the hour.

Answered By: Kusalananda
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.