クローン可能なOR条件

クローン可能なOR条件

クローン可能なパラメータは「AND」条件として機能するようです。したがって、例

0 9-5 * * 1-5

「分が 0 であり、時間が 9 から 5 の間であり、日が月曜日から金曜日の間である」という条件が満たされた場合に実行されます。

私が欲しいのは「または」関数です。そうすれば、「月曜日から金曜日まで、または月の 8 日に実行する」ことができます。そのような関数は存在しますか?

エントリを 2 つ追加できることはわかっていますが、エントリが多すぎると忘れてしまうものが増えてしまいます。

答え1

私が言いたかったのは、「(カンマ) を使う」,です。man 5 crontab

Lists are allowed.
A list is a set of numbers  (or  ranges)  separated  by  commas.
Examples:  "1,2,5,9","0-4,8-12".

しかし、あなたのケースは少し複雑なので、次の機能を利用できます。

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.

したがって、あなたの場合は、 と記述できます0 9-5 8 * 1-5。これにより、コマンドは毎月 8 日と月曜日から金曜日まで毎日実行されます。

test別の解決策としては、 ( man bash、セクション条件式、および)を使用することですman date

# Run on every second Saturday of the month:
   0 4 8-14 * *    test $(date +%u) -eq 6 && echo "2nd Saturday"

関連情報