随机Cron工作 [英] random cron job

查看:88
本文介绍了随机Cron工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个script1,它将每天随机执行一次script2。
我希望每天随机执行30次脚本2。
script1将在cron作业中设置。
有人可以帮忙实现它吗?
PS我不是程序员,所以需要准备一些东西,请

I need a script1 that will execute script2 at random times a day. I'm looking to execute the script2 around 30 times a day within random times. script1 will be set in the cron job. Could someone please help how to make it happen? PS I am not a programmer, so would need something ready to go, please

推荐答案

Seth的解决方案肯定有效,但是每天执行的次数会有所不同。如果您肯定要执行30次,而不是更多而不是更少,我建议使用cron条目,例如

Seth's solution certainly works, but the number of executions per day will differ. If you want definitely 30 executions, not more and not less, I propose using a cron entry like

0 0 * * * gen-executions.sh

和脚本 gen-executions.sh

#!/bin/bash
for number in $(seq 30)
do
    hour=$(( ${RANDOM}*24/32768 ))
    minute=$(( ${RANDOM}*60/32768 ))
    at -f /path/to/script.sh $(printf "%02d" ${hour}):$(printf "%02d" ${minute})
done

这会在一天中的随机时间使用at生成正好30次 /path/to/script.sh 的执行。

This generates exactly 30 executions of /path/to/script.sh at random times of the day using at.

这篇关于随机Cron工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆