$shibayu36->blog;

クラスター株式会社のソフトウェアエンジニアです。エンジニアリングや読書などについて書いています。

/etc/cron.d/以下にドットを含むファイルを配置しても無視される

 先日、/etc/cron.d/にファイルを設定してるのに、何故かcronが起動してくれないという問題があった。その時は/etc/cron.d/crontab.develというファイルを配置していた。

 何でかなーと思ってman cronしてたらこういう記述を見つけた

  As described above, the files under these directories have to be pass some sanity checks including the following: be executable, be owned by root, not be writable by group or other and, if symlinks, point to files owned by root. Additionally, the file names must conform to the filename requirements of run-parts: they must be entirely made up of letters, digits and can only contain the special signs underscores ('_') and hyphens ('-'). Any file that does not conform to these requirements will not be executed by run-parts. For example, any file containing dots will be ignored. This is done to prevent cron from running any of the files that are left by the Debian package management system when handling files in /etc/cron.d/ as configuration files (i.e. files ending in .dpkg-dist, .dpkg-orig, and .dpkg-new).

 つまり

  • 置くファイルは、実行権限あり + root所有 + groupとotherは書き込み権限なし
  • symlinkにした時は、先のファイルがroot所有
  • ファイル名にはletters, digits, -, _しか使えない
    • つまり.が入ってるとだめ
    • For example, any file containing dots will be ignored.

ということっぽい。もちろんcronの実装によるという話になるだろうけど、今回はdebianのVixie Cronでman cronしてた。

 というわけで調べた結果、crontab.develは.を含むので無視されているようでした。その上で警告も何も出ずにただ動かないという感じで全く気づかなかった。アプリケーションの設計をする時はこういう風になんか失敗したら無視するんじゃなくて警告をきちんと出さないと辛いんだなと思った。それかせめてドキュメントじゃなくてconfigtest的な何かが欲しい。

 あと関係ないけど underscores ('_') and hyphens ('-') がかわいい感じだった。