結論
VMware vSphere Hypervisorのdateコマンドは+1 day
という表記が使えない。日本時間で月末の23時0分に実行したいコマンドがある場合、/var/spool/cron/crontabs/root
は以下の通り。
0 14 * * * test $( date -d 24:00 +%d ) -eq 01 && 実行したいコマンド
以下、2017/11/28に色々試した記録。
CentOSのdate
date -d '+1 day'
2017年 11月 29日 水曜日 16:40:02 JST
翌日の日付を取得できている。
VMware vSphere Hypervisor 6.5のdate
date -d '+1 day'
date: invalid date '+1 day'
CentOSと同じ表記ではエラーになる。
BusyBox v1.22.1 (2016-03-26 07:03:26 PDT) multi-call binary.
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string
SPEC='date' (default) for date only,
'hours', 'minutes', or 'seconds' for date and
time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats:
hh:mm[:ss]
[YYYY.]MM.DD-hh:mm[:ss]
YYYY-MM-DD hh:mm[:ss]
[[[[[YY]YY]MM]DD]hh]mm[.ss]
'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
Recognized TIME formats:hh:mm[:ss]
とあったので、+24:00(秒は省略)としてみた。
date -d +24:00
Wed Nov 29 00:00:00 UTC 2017
翌日の日付を取得できた。+はなくてもいいようだ。
date -d 25:00
Wed Nov 29 01:00:00 UTC 2017
実際に /etc/rc.local.d/local.sh に追記した部分
cat<<_EOT_>>/var/spool/cron/crontabs/root
0 16 * * * test \$( date -d 24:00 +%d ) -eq 01 && /bin/sh 実行したいコマンド
_EOT_
cronを再起動する処理は諸説あるので省略。