2013年5月1日水曜日

crontabの中で"%"を使用したい場合はエスケープする必要がある

知らなかった…
The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

(ref. http://linux.die.net/man/5/crontab)

たとえば
`date --date '1 day ago' +'%Y-%m-%d'`
みたいにdateコマンドの出力書式を指定したい時などに”%"を使用しますが、crontabに記載したい場合は以下のようにエスケープしてあげる必要があります。
`date --date '1 day ago' +'\%Y-\%m-\%d'`


0 件のコメント:

コメントを投稿