crontab脚本失败:文件结束意外(期待")")调用$(date)时

时间:2016-07-20 17:35:19

标签: bash cron goaccess

我想添加

0 5 1 * * goaccess -f /var/log/nginx/access.log -a > /home/xan/reports/report-week-$(date +%Y.%m.%d).html

但是crontab总是抱怨:

Subject: Cron <root@deimos> goaccess -f /var/log/nginx/access.log -a > /home/xan/reports/report-week-$(date +
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <E1bIogT-0001FX-9n@deimos>
Date: Fri, 01 Jul 2016 05:00:01 +0200

/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

这样做的正确语法是什么?

1 个答案:

答案 0 :(得分:3)

%在crontab中具有特殊含义(它代表换行符),因此您需要对其进行转义以指定文字百分号。

 0 5 1 * * goaccess ... > /home/xan/reports/report-week-$(date +\%Y.\%m.\%d).html