bashcrongoaccess

crontab script fail: end of file unexpected (expecting ")") when call $(date)


I want to add

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

but crontab always complains about that:

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

What the proper syntax to do that?


Solution

  • % has special meaning in a crontab (it represents a newline), so you need to escape it to specify a literal percent sign.

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