Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments for Randomly spacing cron jobs #1646

Open
sethjensen1 opened this issue Jun 30, 2020 · 4 comments
Open

Comments for Randomly spacing cron jobs #1646

sethjensen1 opened this issue Jun 30, 2020 · 4 comments

Comments

@sethjensen1
Copy link
Contributor

sethjensen1 commented Jun 30, 2020

Comments for https://www.endpointdev.com/blog/2020/06/randomly-spacing-cron-jobs/
By Jon Jensen

To enter a comment:

  1. Log in to GitHub
  2. Leave a comment on this issue.
@ghost
Copy link

ghost commented Jul 2, 2020

We have a bunch of systems all around the world where we want to perform backups at 12:00, 16:00, and 20:00 local time each day. We had noticed that at the top of most hours the backup server started feeling a bit taxed because of so many systems hitting it all at once, so we implemented a random 999 second start time delay for the backup routine.

We have been using the following to set our randomness:

sleep $(tr -cd 0-9 </dev/urandom | head -c 3)

I must say that using RANDOM sure seems easier:

sleep $(( RANDOM % 999 ))

@JamesUoM
Copy link

JamesUoM commented Feb 1, 2021

If you deploy using Ansible or similar you can create the cronjob with a random offset for each host that you are configuring.

@FlorinAndrei
Copy link

On Ubuntu 16.04, the only syntax that worked was:

echo 'sleep $(( $RANDOM \% 600 ))' | bash; /path/to/executable

@jonjensen
Copy link
Member

I am happy to see that cronie, the default cron daemon on the RHEL family (CentOS Stream/Rocky/Alma/Oracle) versions 8 and 9 now support the OpenBSD syntax ~ for a random value within a range!

The feature was added to cronie in Git on 2021-11-08 and appeared on 2022-05-31 in cronie 1.5.7-7 on CentOS Stream 9 and on 2022-05-02 in cronie 1.5.2-7 on CentOS Stream 8. Strange to see it appears there but not yet in Fedora.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants