我正在从事一个新的项目,我想设置一个cron运行每6-8个小时在一个随机的分钟。任何关于实现这一目标的最佳方法的建议都将不胜感激。
发布于 2018-08-24 08:38:52
让我们每6小时运行一次cron:
0 */6 * * * /path/to/script.sh
现在,在您的bash脚本中:
#!/bin/bash
maxdelay=$((2*60)) # 2 hours converted to minutes
delay=$(($RANDOM%maxdelay)) # a random delay
(sleep $((delay*60)); /path/to/script.sh) & # background a subshell to wait, then run the script您还可以使用anacron来实现RANDOM_DELAY功能。
https://stackoverflow.com/questions/51995445
复制相似问题