Reputation: 997
I have created a cron job in which it runs a command within random value (Example 10 mins) at 11pm everyday. I found this example online but I can not find reference.
What I have that doesn't work
SHELL=/bin/bash
PATH=/usr/bin:$PATH
LOCAL_CONFIG_DIR=/user/folder
0 11 * * * sleep $(($RANDOM \% 10))m && python /user/folder/file.py
The following works but does not run at random 10 mins:
SHELL=/bin/bash
PATH=/usr/bin:$PATH
LOCAL_CONFIG_DIR=/user/folder
0 11 * * * python /user/folder/file.py
Wonder if my issue is with $Random
?
Upvotes: 1
Views: 1141
Reputation: 2351
I'm not really good with bash, but You surely can implement sleep inside your python scipt.
import random
import time
time.sleep(random.randint(1, 10)*60)
#Your actual script goes here
Upvotes: 2