vendredi 6 mars 2020

How to randomize min or hr in cron?

My requirement is to execute script in Random time always (every sunday). Is it possible to shuffle minutes & hours in crontab via shuf or Random.?

I don't want to keep sleep with Random or shuf (as in below cron entry), beacuse the cron job process would have start early morning in all the hosts(10000+ in count) and it will be up till the process execution finishes.

00 00 * * 7 sleep `shuf -i 1-86400 -n 1`; /bin/sh /home/myscript.sh >/dev/null 2>&1
00 00 * * 7 sleep $(($RANDOM\%86400)); /bin/sh /home/myscript.sh >/dev/null 2>&1
  • also $RANDOM is a 16 bit number and has limited range

Is there any better option where i can randomize or shuffle minute & hour in crontab entry , or any other way to handle this ?




Aucun commentaire:

Enregistrer un commentaire