linux中的crontab中日期和星期条件测试,linuxcrontab


crontab表达式,前面四项的关系之间为and的关系,需要同时满足才能执行;

但星期那一项与前面月份日期是or的关系,只需满足其一即执行;

文档中是这样写的:

 Note: The day of a command's execution can be specified by two fields — day of month, and day of  week.   If  both       fields  are  restricted (i.e., aren't *), the command will be run when either field matches the 
current time.  For       example,       ``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.       One can, however, achieve the desired result by adding a test to the command (see the last example in EXAMPLE CRON       FILE below).

测试:测试时间为2月8号周四

当前时间是2月8号周四,可以看到如果日期和星期同时填写了的话,首先满足星期5的条件,脚本会在9号开始执行。

相关内容