Fizix is mental floss

主に物理の話を書いていくつもりです

Debianのcronでは実行ファイル名に英数字・アンダースコア・ハイフンのみ使える

起こったこと

Debianでcrontabに定期実行したいシェルスクリプトを追加しても実行されず、エラーログも出ず、かなり悩んだ。

原因

Debianのcronは実行できるファイル名に制限があるため。

man cronすると、DEBIAN SPECIFICの項目に、

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).

とある。つまり、ファイル名に使える文字は

  • 英数字
  • _ (アンダースコア)
  • - (ハイフン) だけということ。

ファイル名から.shを消したらちゃんと実行された。

余談

Debianのパッケージマネージャが作ったファイルを間違って実行しないためにそういう仕様にしている、と書いてありますけど、そんなミス起こるんですかね?