L
これがDebianのcron実装に許可されている特殊文字の1つかどうか疑問に思います。毎月最後の日に実行するcronを設定しようとしています。
「L」は「最後」を意味する。曜日フィールドに使用される場合、その月の「最後の金曜日」(「5L」)などの構造を指定できます。日付フィールドには、その月の最終日を指定します。
注:Lは非標準文字であり、一部のcron実装(Quartz Javaスケジューラ)にのみ存在します。
そうでない場合は、毎月最後の日に実行するようにクローンをどのように設定しますか? 3つの異なる項目をお勧めしますか?stackoverflowのこのソリューション?
ベストアンサー1
Debian の Cron エントリはman 5 crontab
crontab のマニュアルページ ( ) に記載されています。 Debian は Vixie の cron を使用し、マンページには次のように記載されています。
The crontab syntax does not make it possible to define all possible
periods one could image off. For example, it is not straightforward to
define the last weekday of a month. If a task needs to be run in a spe-
cific period of time that cannot be defined in the crontab syntaxs the
best approach would be to have the program itself check the date and
time information and continue execution only if the period matches the
desired one.
If the program itself cannot do the checks then a wrapper script would
be required. Useful tools that could be used for date analysis are ncal
or calendar For example, to run a program the last Saturday of every
month you could use the following wrapper code:
0 4 * * Sat [ "$(date +%e)" = "`ncal | grep $(date +%a | sed -e 's/.$//')
| sed -e 's/^.*\s\([0-9]\+\)\s*$/\1/'`" ] && echo "Last Saturday" &&
program_to_run
したがって、次のように作業します。
0 0 * * * perl -MTime::Local -e
'exit 1 if (((localtime(time()+60*60*24))[3]) < 2);' || program_to_run