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

step in crontab doesn't function as expected when it isn't an even divisor of range #142

Closed
jikamens opened this issue Mar 11, 2023 · 5 comments

Comments

@jikamens
Copy link
Contributor

jikamens commented Mar 11, 2023

If I specify */59 * * * * in a crontab, then I expect the job to run every 59 minutes, with minute of the time the job executes decreasing by one minute every hour. For example, at some point the sequence of run times might be 13:02, 14:01, 15:00, 15:59, etc.

Instead, what happens is that the job runs every :00 and :59 of the hour, which means that it runs twice per hour, one minute apart.

This is, at best, unexpected behavior given what it says in the man page, and the man page should be updated to reflect it. At worst, it's a bug. I, personally, would certainly prefer for this to work as described in the first paragraph.

@t8m
Copy link
Member

t8m commented Mar 13, 2023

This implementation was there basically forever and I do not think changing it at this point makes sense. So yeah, this is a documenation issue.

@t8m t8m closed this as completed in 94b8c3e Mar 13, 2023
@jikamens
Copy link
Contributor Author

jikamens commented Mar 13, 2023

Yeah, I took a look at the code when submitting this and I figured that's what you would say. ;-) Certainly too much work / disruption to change the behavior.

Having said that, is somewhere in the distribution, either the man page or somewhere else, where it would be appropriate to give examples of how to implement the desired frequency? Something like this:

* * * * * if [ $(expr \( $(date +\%s) / 60 \) \% 58) = 0 ]; then echo this runs every 58 minutes; fi
* * * * * if [ $(expr \( $(date +\%s) / 3600 \) \% 23) = 0 ]; then echo this runs every 23 hours; fi

ETA: I originally tried to use + $RANDOM_DELAY in this example but that apparently doesn't work? Not sure why.

@t8m
Copy link
Member

t8m commented Mar 13, 2023

The second example is still not correct - You should use something like 30 * * * * .... otherwise it would be run for every minute in every 23rd hour.

Not sure what would you like to achieve with $RANDOM_DELAY as that would be a fixed value anyway.

I think it could be placed somewhere in crontab(5) in NOTES section perhaps.

@jikamens
Copy link
Contributor Author

The second example is still not correct - You should use something like 30 * * * * .... otherwise it would be run for every minute in every 23rd hour.

Good catch, thanks. New examples:

* * * * * if [ $(expr \( $(date +\%s) / 60 \) \% 58) = 0 ]; then echo this runs every 58 minutes; fi
0 * * * * if [ $(expr \( $(date +\%s) / 3600 \) \% 23) = 0 ]; then echo this runs every 23 hours on the hour; fi

Not sure what would you like to achieve with $RANDOM_DELAY as that would be a fixed value anyway.

Upon further reflection I think I misunderstood what RANDOM_DELAY is. I thought it was set to a static random number I could add to offset the modulus calculation, but it appears that it's a variable that the user sets to affect scheduling behavior, not a variable that crond sets that the user can use in their rules.

I think it could be placed somewhere in crontab(5) in NOTES section perhaps

Sounds reasonable. Would you take a PR if I submit one?

@t8m
Copy link
Member

t8m commented Mar 13, 2023

Sounds reasonable. Would you take a PR if I submit one?

yes, sure

jikamens added a commit to jikamens/cronie that referenced this issue Sep 17, 2023
Add a NOTES section explaining how you can run a job, e.g., every 58
minutes or every 23 hours, since the /# skip syntax doesn't support
that.

As per cronie-crond#142.
t8m pushed a commit that referenced this issue Sep 18, 2023
Add a NOTES section explaining how you can run a job, e.g., every 58
minutes or every 23 hours, since the /# skip syntax doesn't support
that.

As per #142.
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

2 participants