I am going to set crontab for auto renewal of lets-encrypt certificate. I have centos7.
Following is my command for crontab.
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew
I know only thing is certbot renew
will renew the certificate prior expiry date. And 0 0,12 * * *
is a cron time, this cron will run noon & midnight per day.
What is the use of this python command? Simply I don't know following part of cron.
python -c 'import random; import time; time.sleep(random.random() * 3600)'
It sleeps for on average half an hour, presumably to prevent all bots in the world from hitting the server exactly on the hour when they want an update.
The argument to time.sleep()
is a number of seconds, and the randomization picks a value between 0 and 3600.
If you had Bash you could do something similar with sleep $((RANDOM/10))
; but cron
jobs by definition run /bin/sh
, not Bash. (RANDOM
returns an integer between 0 and 32767 - the proper divisor would be something like 9.1; but Bash only supports integer arithmetic.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With