special cron expression: how to make an exception?

两盒软妹~` 提交于 2020-01-15 10:16:24

问题


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

but I don't know how I can translate my exception into the cron syntax, any tips?


回答1:


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

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"

So your cron would be

30 5 * * 2 /path/to/script # comment: script conditional in place to not run on the 1st



回答2:


You can set the "day of month" field to the range 2-31, effectively excluding the first day. This should do it:

50 3 2-31 * 2 MyCommand


来源:https://stackoverflow.com/questions/24508099/special-cron-expression-how-to-make-an-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!