bash - crontab 脚本失败 : end of file unexpected (expecting ")") when call $(date)

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

执行此操作的正确语法是什么?

最佳答案

% 在 crontab 中有特殊含义(它代表一个换行符),所以你需要将它转义以指定文字百分号。

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

关于bash - crontab 脚本失败 : end of file unexpected (expecting ")") when call $(date),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38487179/

相关文章:

mysql - 如何使用 bash 文本处理命令将一个字符的单词元素转换为两个字符的单词元素?

linux - Bash 在用 sed 删除行后插入字符串

r - .Rprofile 未在 cron 下调用

php - cron php如何停止附加到文件的标题

linux - 如何使用 GoAccess 正确过滤我的访问日志?

git - 我的自定义 git 子命令已停止工作

Ruby:实时打印系统输出?

linux - 如何在 Amazon Linux AMI 上设置 cron 作业

apache - 简单的 goaccess 日志解析不起作用

logging - 如何使用goaccess解析多个日志nginx文件