2

I want schedule with cron a task to be ran ONCE in between a certain tange of hours, not every hour in a range.

Example: I want it may run ONCE between 9 to 12 hours, single time. Better if I can run the task ONCE between 9 to 12 hours and random minute as well. I don't want can be predictable, but I want keep control about in which range of hours it will be fired.

I tried:

# m h  dom mon dow   command
00-59 09-12 * * 2 /home/osmc/play.sh

But it ran every minute, between 00 and 59, for every hour between 9 to 12 (not desired)

Any idea how I can do so?

Alshira
  • 33
  • 1
  • 5

1 Answers1

2

If you like to stick with cron, you could do the following:

0 9 * * 2 sleep $(( RANDOM \% 10800)); /home/osmc/play.sh

The job will start at 9AM, and delays the script for upto 10800 seconds, which is 3 hours.

Another solution found here:

Cron jobs and random times, within given hours

Bonsi
  • 48
  • 4