本文介绍了特殊cron表达式:如何使异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我让cron每天凌晨3:50执行一个任务,除了一个星期二与这个月的第一天相符:
I made a cron to execute a task every tuesday at 3:50 AM - except a tuesday which coincides with the first day of the month:
50 3 * * 2 MyCommand
但我不知道
推荐答案
你可以在你的脚本中添加一个条件语句吗?我会这样做。
Can you put a conditional in your script? I would do that. And in your cron you can comment that it won't run on the first per your script directions
例如,在bash中你可以这样做:
As an example, in bash you can do this:
#!/bin/bash
dayofmonth=`date +"%d"`
if [ $dayofmonth == "01" ];
then
# do not run, exit
exit
fi
# otherwise go on
echo "it is not the first"
因此,您的cron将是
So your cron would be
30 5 * * 2 /path/to/script # comment: script conditional in place to not run on the 1st
这篇关于特殊cron表达式:如何使异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!