Cron jobs and random times, within given hours

后端 未结 12 2319
甜味超标
甜味超标 2020-11-27 11:02

I need the ability to run a PHP script 20 times a day at completely random times. I also want it to run only between 9am - 11pm.

I\'m familiar with creating cron job

12条回答
  •  臣服心动
    2020-11-27 11:16

    I ended up using sleep $(( 1$(date +%N) % 60 )) ; dostuffs (compatible with bash & sh)

    The 1 prefix is to force NON base 8 interpretation of date +%N (e.g. 00551454)

    Do not forget to escape % using \% in a crontab file

    * * * * *  nobody  sleep $(( 1$(date +\%N) \% 60 )) ; dostuffs 
    

提交回复
热议问题