I want to run my ruby script x times a day (the number might change) on my linux box. What would be the best way to do so if I do not want it to happen at the same time? I want the time (hour and minute) to be random
I was thinking of using at command. The script would be called by at in x hours/minutes or so and then the script would set up another call by at. Not sure if there is any better way or only ruby way.
I’d consider using the
atprogram to run the programs (instead of usingcrondirectly, becausecronreally only works on a fixed schedule). I’d also create a program (I’d use Perl; you’ll use Ruby) to schedule a random delay until the next time the job is executed.You’ll need to consider whether it is crucial that the job is executed ‘x’ times in 24 hours, and how the randomness should work. What is the range of variation in times. For example, you might have a
cronjob run at midnight plus 7 minutes, say, which then schedules ‘x’atjobs spaced evenly through the day, with a random deviation in the schedule of ±30 minutes. Or you might prefer an alternative that schedules a the jobs with an average gap of 24/x hours and a random deviation of some amount. The difference is that the first mechanism guarantees that you get x events in the day (unless you make things too extreme); the second might sometimes only get x-1 events, or x+1 events, in 24 hours.