带有日期后缀的cron命令?

时间:2012-12-20 23:39:04

标签: unix cron crontab

在命令行中,我能够做到

cp htlog.out test.$(date '+%m%d%Y')

但是当我尝试像这样crontab时:

37 17 * * 1-5 cd the/dir && cp htlog.out test.$(date "+%m%d%Y")

来自CRON DAEMON的以下消息失败:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file

我在命令后确实有终点线。这个crontab条目有什么问题?

1 个答案:

答案 0 :(得分:3)

%中的{p> crontab具有特殊含义,应该反斜杠,所以:

37 17 * * 1-5 cd the/dir && cp htlog.out test.$(date "+\%m\%d\%Y")

来自man 5 crontab

  

命令中的“%”字符,除非使用反斜杠进行转义   *(),将更改为换行符,并且第一个%之后的所有数据将作为标准输入发送到命令。

相关问题