Crontab设置——每55分钟执行一次脚本

时间:2021-06-09 01:06:12

I found a interesting thing during creation of my crontab setting.

在创建crontab设置时,我发现了一件有趣的事情。

I used this command:

我使用这个命令:

crontab -e

and fill this line:

填补这一行:

*/55 * * * * export DISPLAY=:0 && /home/user/Documents/script.sh $2>/dev/null

My idea was create scheduler, which start script.sh every 55 minutes.

我的想法是创建调度程序,启动脚本。sh每个55分钟。

But this script is execute in this times (for example):

但是这个脚本是在这个时候执行的(例如):

08:55, 09:00, 09:05, 09:55, 10:00, 10:05, ...

and I don't know why.

我不知道为什么。

Can someone explain me that?

谁能给我解释一下吗?

3 个解决方案

#1


2  

Replace the script like this and it should work.

像这样替换脚本,它应该可以工作。

 */5 * * * * [ $(( $(date +%s) / 60 % 55 )) -eq 0 ] && export DISPLAY=:0 && /home/user/Documents/script.sh $2>/dev/null

minute-hour-day-month-year

minute-hour-day-month-year

*   any value
,   value list separator
-   range of values
/   step values

#2


0  

so every 5 minutes it will do this:

每5分钟它就会这么做:

number of seconds elapsed since 1. 1. 1970 will divided by 60 = how many minutes

从1开始经过的秒数。1。1970年除以60 =多少分钟

echo $(date +%s) 1476201056 ... second

echo $(日期+%s) 1476201056…第二个

echo $(( $(date +%s) / 60 )) 24603351 ... minutes

echo $($($(日期+%s) / 60) 24603351…分钟

after that it will use modulo on count of minutes

在那之后,它将使用模块化计数分钟

When result of modulo is 0, it will send TRUE value.

当modulo的结果为0时,它将发送真实值。

And it is a typical logical AND

这是一个典型的逻辑

[ $((......)) -eq 0 ] && export DISPLAY.. && .../script.sh

[$((……)-eq 0] &导出显示。& &…/ script.sh

Thank you.

谢谢你!

It is really helpful :)

这真的很有帮助:

#3


0  

Another option is a self-replicating 'at' job. Only advantage over cron is that it is less obvious, and also if you needed it to kick off not every X minutes, but X minutes after the last job completed. So your script will just contain a line to create a new 'at' job before it exits. Something like:

另一个选择是自我复制的“at”工作。与cron相比,它唯一的优势是它不那么明显,而且如果你需要它不是每X分钟就开始,而是在最后一项工作完成后的X分钟。因此,您的脚本将包含一条线,在它退出之前创建一个新的“at”作业。喜欢的东西:

echo "/full/path/to/my/script > /root/myScript.at.log" | at now + X minutes

#1


2  

Replace the script like this and it should work.

像这样替换脚本,它应该可以工作。

 */5 * * * * [ $(( $(date +%s) / 60 % 55 )) -eq 0 ] && export DISPLAY=:0 && /home/user/Documents/script.sh $2>/dev/null

minute-hour-day-month-year

minute-hour-day-month-year

*   any value
,   value list separator
-   range of values
/   step values

#2


0  

so every 5 minutes it will do this:

每5分钟它就会这么做:

number of seconds elapsed since 1. 1. 1970 will divided by 60 = how many minutes

从1开始经过的秒数。1。1970年除以60 =多少分钟

echo $(date +%s) 1476201056 ... second

echo $(日期+%s) 1476201056…第二个

echo $(( $(date +%s) / 60 )) 24603351 ... minutes

echo $($($(日期+%s) / 60) 24603351…分钟

after that it will use modulo on count of minutes

在那之后,它将使用模块化计数分钟

When result of modulo is 0, it will send TRUE value.

当modulo的结果为0时,它将发送真实值。

And it is a typical logical AND

这是一个典型的逻辑

[ $((......)) -eq 0 ] && export DISPLAY.. && .../script.sh

[$((……)-eq 0] &导出显示。& &…/ script.sh

Thank you.

谢谢你!

It is really helpful :)

这真的很有帮助:

#3


0  

Another option is a self-replicating 'at' job. Only advantage over cron is that it is less obvious, and also if you needed it to kick off not every X minutes, but X minutes after the last job completed. So your script will just contain a line to create a new 'at' job before it exits. Something like:

另一个选择是自我复制的“at”工作。与cron相比,它唯一的优势是它不那么明显,而且如果你需要它不是每X分钟就开始,而是在最后一项工作完成后的X分钟。因此,您的脚本将包含一条线,在它退出之前创建一个新的“at”作业。喜欢的东西:

echo "/full/path/to/my/script > /root/myScript.at.log" | at now + X minutes